谁给个封装分页的例子!!!!!
1条回答 默认 最新
iteye_11009 2011-05-14 18:37关注import java.util.List;
public class PageUtil {
private int pageSize=20;//每页显示的条数 默认20private int recordCount;//记录总数 private int currentPage;//当前页 private int pageIndex;//每页的第一条记录编号 private List<?> pageList;//每页的记录集 private int totalPage;//总页数 public int getPageSize() { return pageSize; } public void setPageSize(int pageSize) { this.pageSize = pageSize; } public int getRecordCount() { return recordCount; } public void setRecordCount(int recordCount) { this.recordCount = recordCount; } public int getCurrentPage() { return currentPage; } public void setCurrentPage(int currentPage) { this.currentPage = currentPage; } public int getPageIndex() { return pageIndex; } public void setPageIndex(int pageIndex) { this.pageIndex = pageIndex; } public List<?> getPageList() { return pageList; } public void setPageList(List<?> pageList) { this.pageList = pageList; } public int getTotalPage() { return totalPage; } public void setTotalPage(int totalPage) { this.totalPage = totalPage; } //初始化 currentPage 当前页,pageSize 每页大小,recordCount 总记录数,pageIndex 每页第一条记录序号 public void init(int currentPage,int pageSize,int recordCount){ this.currentPage=currentPage>0?currentPage:1;//设置当前页 this.pageSize=pageSize;//设置每页大小 this.recordCount=recordCount;//设置总记录数 this.pageIndex=(currentPage-1)*pageSize;//设置每页第一条记录 if(recordCount%pageSize == 0){ this.totalPage = recordCount/pageSize;}else{
this.totalPage = recordCount/pageSize+1;
}
this.pageIndex=(currentPage-1)*pageSize;//设置每页第一条记录
this.totalPage=(0 == recordCount%pageSize) ? recordCount/pageSize : (recordCount/pageSize+1);
if(currentPage>totalPage){
currentPage=totalPage;
}本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报