|
|
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;
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|