分页的工具类

package cn.et.model;


import java.util.List;


/**
 * 分页的参数
 * @author Administrator
 *
 */
public class PageTools {
/**
* 构造参数
* @param curPage 页面传入的当前页
* @param totalCount 数据库查询的总记录数
* @param pageCount     每页显示的条数
*/
public PageTools(Integer curPage,Integer totalCount,Integer pageCount){
this.curPage=curPage;
this.totalCount=totalCount;
this.pageCount=pageCount==null?this.pageCount:pageCount;
this.prePage=(curPage==1?1:curPage-1);
this.totalPage=totalCount%this.pageCount==0?totalCount/this.pageCount:totalCount/this.pageCount+1;
this.nextPage=(curPage==totalPage)?totalPage:(curPage+1);
this.startIndex=(curPage-1)*this.pageCount+1;
this.endIndex=curPage*this.pageCount;
}
/**
* 当前页(动态由页面传递的)
*/
private Integer curPage;
/**
* 每页显示条数
*/
private Integer pageCount=10;
/**
* 上一页
*/
private Integer prePage;
/**
* 下一页
*/
private Integer nextPage;
/**
* 总页数
*/
private Integer totalPage;
/**
* 总记录数(从数据库查询出来)
*/
private Integer totalCount;
/**
* 开始索引
*/
private Integer startIndex;
/**
* 结束索引
*/
private Integer endIndex;
/**
* 存储最终查询的数据
*/
private List data;

public Integer getCurPage() {
return curPage;
}
public void setCurPage(Integer curPage) {
this.curPage = curPage;
}
public Integer getPageCount() {
return pageCount;
}
public void setPageCount(Integer pageCount) {
this.pageCount = pageCount;
}
public Integer getPrePage() {
return prePage;
}
public void setPrePage(Integer prePage) {
this.prePage = prePage;
}
public Integer getNextPage() {
return nextPage;
}
public void setNextPage(Integer nextPage) {
this.nextPage = nextPage;
}
public Integer getTotalPage() {
return totalPage;
}
public void setTotalPage(Integer totalPage) {
this.totalPage = totalPage;
}
public Integer getTotalCount() {
return totalCount;
}
public void setTotalCount(Integer totalCount) {
this.totalCount = totalCount;
}

public Integer getStartIndex() {
return startIndex;
}
public void setStartIndex(Integer startIndex) {
this.startIndex = startIndex;
}
public Integer getEndIndex() {
return endIndex;
}
public void setEndIndex(Integer endIndex) {
this.endIndex = endIndex;
}
public List getData() {
return data;
}
public void setData(List data) {
this.data = data;
}

public static void main(String[] args) {
int curPage=6;
int totalCount=26;
int pageCount=5;
PageTools pt=new PageTools(curPage,totalCount,pageCount);

System.out.println(pt.getNextPage());
System.out.println(pt.getPrePage());
System.out.println(pt.getTotalPage());
System.out.println(pt.getStartIndex());
System.out.println(pt.getEndIndex());
}
}















评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值