后台实现:package com.wangzhixuan.utils;
import java.util.List;
import java.util.Map;
/**
* @description:分页实体类 (结合jqery easyui)
* @author:zyp
*/
public class PageInfo {
private final static int PAGESIZE = 10; //默认显示的记录数
private int total; // 总记录
@SuppressWarnings("rawtypes")
private List rows; //显示的记录
private int from;
private int size;
private int nowpage; // 当前页
private int pagesize; // 每页显示的记录数
private Map<String, Object> condition; //查询条件
private String sort = "seq";// 排序字段
private String order = "asc";// asc,desc mybatis Order 关键字
public PageInfo() {
}
//构造方法
public PageInfo(int nowpage, int pagesize) {
//计算当前页
if (nowpage < 0) {
this.nowpage = 1;
} else {
//当前页
this.nowpage = nowpage;
}
//记录每页显示的记录数
if (pagesize < 0) {
this.pagesize = PAGESIZE;
} else {
this.pagesize = pagesize;
}
//计算开始的记录和结束的记录
this.from = (this.nowpage - 1) * this.pagesize;
this.size = this.pagesize;
}
// 构造方法
public PageInfo(int nowpage, int pagesize, String sort, String order) {
// 计算当前页
if (nowpage < 0) {
this.nowpage = 1;
} else {
// 当前页
this.nowpage = nowpage;
}
// 记录每页显示的记录数
if (pagesize < 0) {
this.pagesize = PAGESIZE;
} else {
this.pagesize = pagesize;
}
// 计算开始的记录和结束的记录
this.from = (this.nowpage - 1) * this.pagesize;
this.size = this.pagesize;
// 排序字段,正序还是反序
this.sort = sort;
this.order = order;
}
public int getTotal() {
return total;
}
public void setTotal(int total) {
this.total = total;
}
public List getRows() {
return rows;
}
public void setRows(List rows) {
this.rows = rows;
}
public int getFrom() {
return from;
}
public void setFrom(int from) {
this.from = from;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public int getNowpage() {
return nowpage;
}
public void setNowpage(int nowpage) {
this.nowpage = nowpage;
}
public int getPagesize() {
return pagesize;
}
public void setPagesize(int pagesize) {
this.pagesize = pagesize;
}
public Map<String, Object> getCondition() {
return condition;
}
public void setCondition(Map<String, Object> condition) {
this.condition = condition;
}
public String getSort() {
return sort;
}
public void setSort(String sort) {
this.sort = sort;
}
public String getOrder() {
return order;
}
public void setOrder(String order) {
this.order = order;
}
}
@RequestMapping(value = "/dataGrid", method = RequestMethod.POST)
@ResponseBody
public PageInfo dataGrid(UserVo userVo, Integer page, Integer rows, String sort, String order) {
PageInfo pageInfo = new PageInfo(page, rows);
Map<String, Object> condition = Maps.newHashMap();
if (StringUtils.isNoneBlank(userVo.getName())) {
condition.put("name", userVo.getName());
}
if (userVo.getOrganizationId() != null) {
condition.put("organizationId", userVo.getOrganizationId());
}
if (userVo.getCreatedateStart() != null) {
condition.put("startTime", userVo.getCreatedateStart());
}
if (userVo.getCreatedateEnd() != null) {
condition.put("endTime", userVo.getCreatedateEnd());
}
pageInfo.setCondition(condition);
userService.findDataGrid(pageInfo);
return pageInfo;
}