Authored by simba

update

... ... @@ -11,3 +11,5 @@ monitor-ui-ctrl/.gitignore
monitor-ui-ctrl/.project
.project
monitor-ui-common/.classpath
monitor-ui-ctrl/src/main/java/com/ui/ctrl/host/HostInfoCtrl.java
monitor-ui-ctrl/src/main/resources/META-INF/spring/spring-config-cmdb.xml
... ...
... ... @@ -71,6 +71,10 @@
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
... ...
package com.ui.model;
/**
* service返回信息对象
* @author hp
* 2014-03-11
*/
public class BaseResponse<T> {
private int code = 200;
private String message = "success";
private T data;
public BaseResponse() {}
public BaseResponse(ErrorCode errorCode) {
this.code = errorCode.getCode();
this.message = errorCode.getMessage();
}
public BaseResponse(int code, String message) {
this.code = code;
this.message = message;
}
public BaseResponse(T data) {
this.data = data;
}
public BaseResponse(int code, String message, T data) {
this(code, message);
this.data = data;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
}
... ...
/**
*
*/
package com.ui.model;
import lombok.Data;
/**
* 描述:
*
* @author ping.huang
* 2016年3月31日
*/
@Data
public class ErrorCode extends BaseModel {
public ErrorCode(int code, String message) {
super();
this.code = code;
this.message = message;
}
/**
*
*/
private static final long serialVersionUID = 1665066362288658528L;
private int code;
private String message;
}
... ...
package com.ui.model.rep;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
/**
* 分页对象
* @author ping.huang
*
*/
public class PageBean{
private int pageNo = 1;// 页码,默认是第一页
private int pageSize = 10;// 每页显示的记录数,默认是10
private int totalRecord;// 总记录数
private int totalPage;// 总页数
private int startIndex = 0;//查询的开始行数
private Map<String, Object> params = new HashMap<String, Object>();// 其他的参数我们把它分装成一个Map对象
/**
* 初始化分页信息
*
* @param pageNo
* @param pageSize
* @param o
* @return
*/
public static PageBean initPageInfo(int pageNo, int pageSize, Object o) {
PageBean page = new PageBean();
if (pageNo > 0) {
page.setPageNo(pageNo);
}
if (pageSize > 0) {
page.setPageSize(pageSize);
}
page.setStartIndex((page.getPageNo() - 1) * page.getPageSize());
if (o != null) {
try {
Field[] declaredFields = o.getClass().getDeclaredFields();
for (Field field : declaredFields) {
field.setAccessible(true);
// 过滤内容为空的
if (field.get(o) == null) {
continue;
}
page.getParams().put(field.getName(), field.get(o));
}
} catch (IllegalAccessException e) {
}
}
return page;
}
public int getPageNo() {
return pageNo;
}
public void setPageNo(int pageNo) {
this.pageNo = pageNo;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getTotalRecord() {
return totalRecord;
}
public void setTotalRecord(int totalRecord) {
this.totalRecord = totalRecord;
// 在设置总页数的时候计算出对应的总页数
int totalPage = totalRecord % pageSize == 0 ? totalRecord / pageSize : totalRecord / pageSize + 1;
this.setTotalPage(totalPage);
}
public int getTotalPage() {
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public int getStartIndex() {
return startIndex;
}
public void setStartIndex(int startIndex) {
this.startIndex = startIndex;
}
public Map<String, Object> getParams() {
return params;
}
public void setParams(Map<String, Object> params) {
this.params = params;
}
}
... ...
package com.ui.model.rep;
import java.util.ArrayList;
import java.util.List;
/**
* 统一的分页响应对象 描述:
*
* @author ping.huang 2016年1月25日
*/
public class PageResponse<T> {
private int total;
private int currentPage;
private int pageSize;
private int totalPage;
private List<T> rows = new ArrayList<>();
public PageResponse() {
}
public int getTotal() {
return total;
}
public void setTotal(int total) {
this.total = total;
// 在设置总页数的时候计算出对应的总页数
dealTotalPage();
}
private void dealTotalPage() {
if (total > 0 && pageSize > 0) {
int totalPage = total % pageSize == 0 ? total / pageSize : total / pageSize + 1;
this.setTotalPage(totalPage);
}
}
public int getTotalPage() {
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public List<T> getRows() {
return rows;
}
public void setRows(List<T> rows) {
this.rows = rows;
}
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
}
... ...
package com.ui.model.req;
import lombok.Data;
/**
* Created by yoho on 2016/6/14.
*/
@Data
public class HostInfoReq extends PageRequest {
private String alias;
private String hostIp;
private int groupId;
private String tags;
}
... ...
package com.ui.model.req;
/**
* 统一的分页请求对象 描述:
*
* @author ping.huang 2016年1月25日
*/
public class PageRequest {
private int currentPage = 1;
private int pageSize = 10;
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
if (currentPage <= 1) {
currentPage = 1;
}
this.currentPage = currentPage;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
}
... ...
package com.ui.ctrl;
import com.alibaba.fastjson.JSON;
import com.ui.http.HttpRestClient;
import com.ui.model.BaseResponse;
import com.ui.model.req.HostInfoReq;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* Created by yoho on 2016/6/14.
* 查询机器信息
*/
@Controller
@RequestMapping("hostInfo")
public class HostInfoCtrl {
Logger log = LoggerFactory.getLogger(HostInfoCtrl.class);
@Autowired
HttpRestClient httpRestClient;
@RequestMapping("/getHostInfos")
@ResponseBody
public BaseResponse getHostInfos(HostInfoReq req) throws Exception {
BaseResponse response=httpRestClient.defaultPost("/hostInfo/getHostInfos", req, BaseResponse.class);
System.out.println("*****************************"+ JSON.toJSON(response));
return response;
}
}
... ...
... ... @@ -38,7 +38,8 @@
<div id="sidebar">
<ul>
<li class="active"><a href="#"><i class="icon icon-home"></i> <span>Dashboard</span></a></li>
<li><a href="#" onclick="aa(this)" ><i class="icon icon-th"></i> <span>Tables</span></a></li>
<li><a href="#" onclick="clickMenuToPage(this)" ><i class="icon icon-th"></i> <span>Tables</span></a></li>
<li><a href="#" onclick="clickMenuToPage('/jsp/host/hostInfoList.jsp')" ><i class="icon icon-th"></i> <span>主机信息</span></a></li>
</ul>
</div>
<!-- 右侧具体内容 -->
... ... @@ -47,9 +48,9 @@
</div>
<script type="text/javascript">
function aa(){
function clickMenuToPage(page){
//加载左侧内容
$("#content").load("<%=basePath %>/jsp/table.jsp");
$("#content").load("<%=basePath %>"+page);
}
</script>
</body>
... ...