这次封装,考虑了查询中首页参数不存在的情况,和未指定每页数据量的情况下进行的封装,另外对于总页数的计算也是采用了最新的算法,减少因为数据类型的转换造成的精度缺失问题,使得页面的封装更加科学和精确
public class PageBean {
private List list;
private Integer totalCount;
private Integer pageSize;
private Integer totalPage;
private Integer currentPage;
public PageBean(Integer pageSize, Integer totalPage, Integer currentPage) {
this.pageSize = pageSize;
this.totalPage = totalPage;
this.currentPage = currentPage;
if (currentPage==null) {
this.currentPage=1;
}
if (pageSize==null) {
this.pageSize=3;
}
if (this.currentPage<1) {
this.currentPage=1;
}
this.totalPage=(this.totalCount+this.pageSize-1)/this.pageSize;
if (this.currentPage>this.totalPage) {
this.currentPage=this.totalPage;
}
}
public Integer getFirstResult(){
return (currentPage-1)*pageSize;
}
public List getList() {
return list;
}
public void setList(List list) {
this.list = list;
}
public Integer getTotalCount() {
return totalCount;
}
public void setTotalCount(Integer totalCount) {
this.totalCount = totalCount;
}
public Integer getPageSize() {
return pageSize;
}
public void setPageSize(Integer pageSize) {
this.pageSize = pageSize;
}
public Integer getTotalPage() {
return totalPage;
}
public void setTotalPage(Integer totalPage) {
this.totalPage = totalPage;
}
public Integer getCurrentPage() {
return currentPage;
}
public void setCurrentPage(Integer currentPage) {
this.currentPage = currentPage;
}
@Override
public String toString() {
return "PageBean [list=" + list + ", totalCount=" + totalCount + ", pageSize=" + pageSize + ", totalPage="
+ totalPage + ", currentPage=" + currentPage + "]";
}
}