//13年写的,今天(17)拷贝到博客园
package com.sicdt.sicsign.web.utils; import java.io.Serializable; import java.util.List; /** * @author shizhenwei * * @param <T>用于向前台返还List所用 */ public class PageInfo<T> implements Serializable { private static final long serialVersionUID = 1L; //每页显示的记录数 private Integer pageSize; //当前页码数 private Integer pageNum; //总记录数 private Integer rowCount; //总页码数 private Integer pageCount; //查询的时候从多少记录开始 private Integer rowStart; //每页显示多少页码 private Integer everyPageTabsCount; //每页显示的开始页码数 private Integer everyPageStart; //每页显示的结束页码数 private Integer everyPageEnd; //是否有上一页 private boolean hasPrevious = false; //首页 private Integer firstPageNum; //上一页 private Integer priviousPageNum; //是否有下一页 private boolean hasNext = false; //下一页 private Integer nextPageNum; //尾页 private Integer endPageNum; //存放本次分页查询出来的数据 private List<T> list; /** * 通过构造器计算出其他属性的值 * @param pageSize * @param pageNum * @param rowCount */ public PageInfo(Integer pageNum,Integer pageSize,Integer rowCount,Integer everyPageTabsCount) { //每页显示的记录数 this.pageSize = pageSize == null ? 10 : pageSize; //当前页码数 this.pageNum = pageNum == null ? 1 : pageNum; //总记录数 this.rowCount = rowCount == null ? 0 : rowCount; //每页显示多少页码 默认10,可以set this.everyPageTabsCount = everyPageTabsCount == null ? 10 : everyPageTabsCount; //总页码数 this.pageCount = (int) Math.ceil(this.rowCount * 1.0 / this.pageSize); //判断当前页码数是否大于总页码数 if (this.pageNum > this.pageCount && this.pageCount >= 1) { this.pageNum = this.pageCount; } //查询的时候从多少记录开始 this.rowStart = (this.pageNum - 1) * this.pageSize; //每页显示的开始页码数 this.everyPageStart = (this.pageNum - this.everyPageTabsCount / 2) > 0 ? (this.pageNum - this.everyPageTabsCount / 2) : 1; /***** 无论从第几页开始都会以固定的页数进行显示,当总页数小于固定页数,将全部显示总页数****/ int cenNum = (int) Math.ceil((this.everyPageTabsCount / 2.0)); if(this.pageCount>=this.everyPageTabsCount && this.pageNum<=(this.everyPageTabsCount / 2)){ this.everyPageEnd = this.everyPageTabsCount; }else if(this.pageCount<=this.everyPageTabsCount){ this.everyPageEnd = this.pageCount; }else{ //每页显示的结束页码数 this.everyPageEnd = (this.pageNum + cenNum - 1) > this.pageCount ? this.pageCount : (this.pageNum + cenNum - 1); } if(this.pageCount>=this.everyPageTabsCount && this.pageNum>(this.pageCount-(cenNum - 1))){ this.everyPageStart=this.pageCount-(this.everyPageTabsCount-1); } //是否有上一页 if (this.pageNum > 1) { this.hasPrevious = true; this.firstPageNum = 1; this.priviousPageNum = this.pageNum - 1; } //是否有下一页 if (this.pageNum < this.pageCount) { this.hasNext = true; this.nextPageNum = this.pageNum + 1; this.endPageNum = this.pageCount; } } public Integer getPageSize() { return pageSize; } public Integer getPageNum() { return pageNum; } public Integer getRowCount() { return rowCount; } public Integer getPageCount() { return pageCount; } public Integer getRowStart() { return rowStart; } public Integer getEveryPageStart() { return everyPageStart; } public Integer getEveryPageEnd() { return everyPageEnd; } public boolean isHasPrevious() { return hasPrevious; } public Integer getFirstPageNum() { return firstPageNum; } public Integer getPriviousPageNum() { return priviousPageNum; } public boolean isHasNext() { return hasNext; } public Integer getNextPageNum() { return nextPageNum; } public Integer getEndPageNum() { return endPageNum; } public List<T> getList() { return list; } public void setList(List<T> list) { this.list = list; } public Integer getEveryPageTabsCount() { return everyPageTabsCount; } public void setEveryPageTabsCount(Integer everyPageTabsCount) { this.everyPageTabsCount = everyPageTabsCount; } }