Authored by simba

update

@@ -11,3 +11,5 @@ monitor-ui-ctrl/.gitignore @@ -11,3 +11,5 @@ monitor-ui-ctrl/.gitignore
11 monitor-ui-ctrl/.project 11 monitor-ui-ctrl/.project
12 .project 12 .project
13 monitor-ui-common/.classpath 13 monitor-ui-common/.classpath
  14 +monitor-ui-ctrl/src/main/java/com/ui/ctrl/host/HostInfoCtrl.java
  15 +monitor-ui-ctrl/src/main/resources/META-INF/spring/spring-config-cmdb.xml
@@ -71,6 +71,10 @@ @@ -71,6 +71,10 @@
71 <artifactId>commons-lang</artifactId> 71 <artifactId>commons-lang</artifactId>
72 <version>2.6</version> 72 <version>2.6</version>
73 </dependency> 73 </dependency>
  74 + <dependency>
  75 + <groupId>org.projectlombok</groupId>
  76 + <artifactId>lombok</artifactId>
  77 + </dependency>
74 </dependencies> 78 </dependencies>
75 79
76 80
  1 +package com.ui.model;
  2 +
  3 +/**
  4 + * service返回信息对象
  5 + * @author hp
  6 + * 2014-03-11
  7 + */
  8 +public class BaseResponse<T> {
  9 +
  10 + private int code = 200;
  11 + private String message = "success";
  12 +
  13 + private T data;
  14 +
  15 + public BaseResponse() {}
  16 +
  17 + public BaseResponse(ErrorCode errorCode) {
  18 + this.code = errorCode.getCode();
  19 + this.message = errorCode.getMessage();
  20 + }
  21 +
  22 + public BaseResponse(int code, String message) {
  23 + this.code = code;
  24 + this.message = message;
  25 + }
  26 +
  27 + public BaseResponse(T data) {
  28 + this.data = data;
  29 + }
  30 +
  31 + public BaseResponse(int code, String message, T data) {
  32 + this(code, message);
  33 + this.data = data;
  34 + }
  35 +
  36 + public int getCode() {
  37 + return code;
  38 + }
  39 +
  40 + public void setCode(int code) {
  41 + this.code = code;
  42 + }
  43 +
  44 + public String getMessage() {
  45 + return message;
  46 + }
  47 +
  48 + public void setMessage(String message) {
  49 + this.message = message;
  50 + }
  51 +
  52 + public T getData() {
  53 + return data;
  54 + }
  55 +
  56 + public void setData(T data) {
  57 + this.data = data;
  58 + }
  59 +
  60 +}
  61 +
  1 +/**
  2 + *
  3 + */
  4 +package com.ui.model;
  5 +
  6 +import lombok.Data;
  7 +
  8 +/**
  9 + * 描述:
  10 + *
  11 + * @author ping.huang
  12 + * 2016年3月31日
  13 + */
  14 +@Data
  15 +public class ErrorCode extends BaseModel {
  16 +
  17 + public ErrorCode(int code, String message) {
  18 + super();
  19 + this.code = code;
  20 + this.message = message;
  21 + }
  22 + /**
  23 + *
  24 + */
  25 + private static final long serialVersionUID = 1665066362288658528L;
  26 +
  27 + private int code;
  28 + private String message;
  29 +
  30 +}
  1 +package com.ui.model.rep;
  2 +
  3 +
  4 +import java.lang.reflect.Field;
  5 +import java.util.HashMap;
  6 +import java.util.Map;
  7 +
  8 +/**
  9 + * 分页对象
  10 + * @author ping.huang
  11 + *
  12 + */
  13 +public class PageBean{
  14 +
  15 + private int pageNo = 1;// 页码,默认是第一页
  16 + private int pageSize = 10;// 每页显示的记录数,默认是10
  17 + private int totalRecord;// 总记录数
  18 + private int totalPage;// 总页数
  19 + private int startIndex = 0;//查询的开始行数
  20 +
  21 + private Map<String, Object> params = new HashMap<String, Object>();// 其他的参数我们把它分装成一个Map对象
  22 +
  23 + /**
  24 + * 初始化分页信息
  25 + *
  26 + * @param pageNo
  27 + * @param pageSize
  28 + * @param o
  29 + * @return
  30 + */
  31 + public static PageBean initPageInfo(int pageNo, int pageSize, Object o) {
  32 + PageBean page = new PageBean();
  33 + if (pageNo > 0) {
  34 + page.setPageNo(pageNo);
  35 + }
  36 + if (pageSize > 0) {
  37 + page.setPageSize(pageSize);
  38 + }
  39 + page.setStartIndex((page.getPageNo() - 1) * page.getPageSize());
  40 + if (o != null) {
  41 + try {
  42 + Field[] declaredFields = o.getClass().getDeclaredFields();
  43 + for (Field field : declaredFields) {
  44 + field.setAccessible(true);
  45 + // 过滤内容为空的
  46 + if (field.get(o) == null) {
  47 + continue;
  48 + }
  49 + page.getParams().put(field.getName(), field.get(o));
  50 + }
  51 +
  52 + } catch (IllegalAccessException e) {
  53 + }
  54 + }
  55 + return page;
  56 + }
  57 +
  58 + public int getPageNo() {
  59 + return pageNo;
  60 + }
  61 +
  62 + public void setPageNo(int pageNo) {
  63 + this.pageNo = pageNo;
  64 + }
  65 +
  66 + public int getPageSize() {
  67 + return pageSize;
  68 + }
  69 +
  70 + public void setPageSize(int pageSize) {
  71 + this.pageSize = pageSize;
  72 + }
  73 +
  74 + public int getTotalRecord() {
  75 + return totalRecord;
  76 + }
  77 +
  78 + public void setTotalRecord(int totalRecord) {
  79 + this.totalRecord = totalRecord;
  80 + // 在设置总页数的时候计算出对应的总页数
  81 + int totalPage = totalRecord % pageSize == 0 ? totalRecord / pageSize : totalRecord / pageSize + 1;
  82 + this.setTotalPage(totalPage);
  83 + }
  84 +
  85 + public int getTotalPage() {
  86 + return totalPage;
  87 + }
  88 +
  89 + public void setTotalPage(int totalPage) {
  90 + this.totalPage = totalPage;
  91 + }
  92 +
  93 + public int getStartIndex() {
  94 + return startIndex;
  95 + }
  96 +
  97 + public void setStartIndex(int startIndex) {
  98 + this.startIndex = startIndex;
  99 + }
  100 +
  101 + public Map<String, Object> getParams() {
  102 + return params;
  103 + }
  104 +
  105 + public void setParams(Map<String, Object> params) {
  106 + this.params = params;
  107 + }
  108 +
  109 +}
  1 +package com.ui.model.rep;
  2 +
  3 +import java.util.ArrayList;
  4 +import java.util.List;
  5 +
  6 +/**
  7 + * 统一的分页响应对象 描述:
  8 + *
  9 + * @author ping.huang 2016年1月25日
  10 + */
  11 +public class PageResponse<T> {
  12 +
  13 +
  14 + private int total;
  15 + private int currentPage;
  16 + private int pageSize;
  17 + private int totalPage;
  18 + private List<T> rows = new ArrayList<>();
  19 +
  20 + public PageResponse() {
  21 + }
  22 +
  23 + public int getTotal() {
  24 + return total;
  25 + }
  26 +
  27 + public void setTotal(int total) {
  28 + this.total = total;
  29 + // 在设置总页数的时候计算出对应的总页数
  30 + dealTotalPage();
  31 + }
  32 +
  33 + private void dealTotalPage() {
  34 + if (total > 0 && pageSize > 0) {
  35 + int totalPage = total % pageSize == 0 ? total / pageSize : total / pageSize + 1;
  36 + this.setTotalPage(totalPage);
  37 + }
  38 + }
  39 +
  40 + public int getTotalPage() {
  41 + return totalPage;
  42 + }
  43 +
  44 + public void setTotalPage(int totalPage) {
  45 + this.totalPage = totalPage;
  46 + }
  47 +
  48 + public List<T> getRows() {
  49 + return rows;
  50 + }
  51 +
  52 + public void setRows(List<T> rows) {
  53 + this.rows = rows;
  54 + }
  55 +
  56 + public int getCurrentPage() {
  57 + return currentPage;
  58 + }
  59 +
  60 + public void setCurrentPage(int currentPage) {
  61 + this.currentPage = currentPage;
  62 + }
  63 +
  64 + public int getPageSize() {
  65 + return pageSize;
  66 + }
  67 +
  68 + public void setPageSize(int pageSize) {
  69 + this.pageSize = pageSize;
  70 + }
  71 +}
  1 +package com.ui.model.req;
  2 +
  3 +import lombok.Data;
  4 +
  5 +/**
  6 + * Created by yoho on 2016/6/14.
  7 + */
  8 +@Data
  9 +public class HostInfoReq extends PageRequest {
  10 +
  11 + private String alias;
  12 +
  13 + private String hostIp;
  14 +
  15 + private int groupId;
  16 +
  17 + private String tags;
  18 +
  19 +}
  1 +package com.ui.model.req;
  2 +
  3 +
  4 +/**
  5 + * 统一的分页请求对象 描述:
  6 + *
  7 + * @author ping.huang 2016年1月25日
  8 + */
  9 +public class PageRequest {
  10 +
  11 + private int currentPage = 1;
  12 + private int pageSize = 10;
  13 +
  14 + public int getCurrentPage() {
  15 + return currentPage;
  16 + }
  17 +
  18 + public void setCurrentPage(int currentPage) {
  19 + if (currentPage <= 1) {
  20 + currentPage = 1;
  21 + }
  22 + this.currentPage = currentPage;
  23 + }
  24 +
  25 + public int getPageSize() {
  26 + return pageSize;
  27 + }
  28 +
  29 + public void setPageSize(int pageSize) {
  30 + this.pageSize = pageSize;
  31 + }
  32 +}
  1 +package com.ui.ctrl;
  2 +
  3 +
  4 +import com.alibaba.fastjson.JSON;
  5 +import com.ui.http.HttpRestClient;
  6 +import com.ui.model.BaseResponse;
  7 +import com.ui.model.req.HostInfoReq;
  8 +import org.slf4j.Logger;
  9 +import org.slf4j.LoggerFactory;
  10 +import org.springframework.beans.factory.annotation.Autowired;
  11 +import org.springframework.stereotype.Controller;
  12 +import org.springframework.web.bind.annotation.RequestMapping;
  13 +import org.springframework.web.bind.annotation.ResponseBody;
  14 +
  15 +/**
  16 + * Created by yoho on 2016/6/14.
  17 + * 查询机器信息
  18 + */
  19 +@Controller
  20 +@RequestMapping("hostInfo")
  21 +public class HostInfoCtrl {
  22 +
  23 + Logger log = LoggerFactory.getLogger(HostInfoCtrl.class);
  24 +
  25 + @Autowired
  26 + HttpRestClient httpRestClient;
  27 +
  28 +
  29 + @RequestMapping("/getHostInfos")
  30 + @ResponseBody
  31 + public BaseResponse getHostInfos(HostInfoReq req) throws Exception {
  32 + BaseResponse response=httpRestClient.defaultPost("/hostInfo/getHostInfos", req, BaseResponse.class);
  33 + System.out.println("*****************************"+ JSON.toJSON(response));
  34 + return response;
  35 + }
  36 +
  37 +
  38 +
  39 +}
  40 +
@@ -38,7 +38,8 @@ @@ -38,7 +38,8 @@
38 <div id="sidebar"> 38 <div id="sidebar">
39 <ul> 39 <ul>
40 <li class="active"><a href="#"><i class="icon icon-home"></i> <span>Dashboard</span></a></li> 40 <li class="active"><a href="#"><i class="icon icon-home"></i> <span>Dashboard</span></a></li>
41 - <li><a href="#" onclick="aa(this)" ><i class="icon icon-th"></i> <span>Tables</span></a></li> 41 + <li><a href="#" onclick="clickMenuToPage(this)" ><i class="icon icon-th"></i> <span>Tables</span></a></li>
  42 + <li><a href="#" onclick="clickMenuToPage('/jsp/host/hostInfoList.jsp')" ><i class="icon icon-th"></i> <span>主机信息</span></a></li>
42 </ul> 43 </ul>
43 </div> 44 </div>
44 <!-- 右侧具体内容 --> 45 <!-- 右侧具体内容 -->
@@ -47,9 +48,9 @@ @@ -47,9 +48,9 @@
47 </div> 48 </div>
48 49
49 <script type="text/javascript"> 50 <script type="text/javascript">
50 - function aa(){ 51 + function clickMenuToPage(page){
51 //加载左侧内容 52 //加载左侧内容
52 - $("#content").load("<%=basePath %>/jsp/table.jsp"); 53 + $("#content").load("<%=basePath %>"+page);
53 } 54 }
54 </script> 55 </script>
55 </body> 56 </body>