分页工具类封装 Posted on 2021-03-29 | In 工具类 | | 次阅读 分页工具类封装123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115```javapackage com.ujiuye.utils;//分页工具类public class PageTool { private int currentPage;//当前页 private int pageSize;//每页显示的条数 自定义大小 private int startIndex;//起始索引 startIndex = (currentPage-1)*pageSize private int totalCount;//总条数 查询数据库得到select count(*) from 表名; private int totalPage;//总页数 计算: (totalCount%pageSize == 0) ? (totalCount/pageSize):(totalCount/pageSize+1) private int prePage;//上一页 currentPage-1 private int nextPage;//下一页 currentPage+1 public PageTool(String currentPage, int totalCount) { this.totalCount = totalCount; //自定义显示的条数 this.pageSize = 3; initCurrentPage(currentPage);//当前页 initTotalPage(); initStartIndex(); initPrePage(); initNextPage(); } //给当前页进行初始化 private void initCurrentPage(String currentPage) { //判断 if(currentPage == null) { this.currentPage = 1; }else { //赋值第几页 this.currentPage = Integer.valueOf(currentPage); } } //计算总页数 private void initTotalPage() { //计算 this.totalPage = (totalCount%pageSize == 0) ? (totalCount/pageSize):(totalCount/pageSize+1); } //上一页 private void initPrePage() { //判断 if(currentPage == 1) { //赋值第一页 this.prePage = 1; }else { this.prePage = currentPage - 1;//2 } } //下一页 private void initNextPage() { //判断 if(currentPage == totalPage) { //赋值第一页 this.nextPage = totalPage; }else { this.nextPage = currentPage + 1; } } //起始索引 private void initStartIndex() { //计算 this.startIndex = (currentPage-1) * pageSize; } public int getCurrentPage() { return currentPage; } public void setCurrentPage(int currentPage) { this.currentPage = currentPage; } public int getPageSize() { return pageSize; } public void setPageSize(int pageSize) { this.pageSize = pageSize; } public int getStartIndex() { return startIndex; } public void setStartIndex(int startIndex) { this.startIndex = startIndex; } public int getTotalCount() { return totalCount; } public void setTotalCount(int totalCount) { this.totalCount = totalCount; } public int getTotalPage() { return totalPage; } public void setTotalPage(int totalPage) { this.totalPage = totalPage; } public int getPrePage() { return prePage; } public void setPrePage(int prePage) { this.prePage = prePage; } public int getNextPage() { return nextPage; } public void setNextPage(int nextPage) { this.nextPage = nextPage; }}```-------------本文结束感谢您的阅读-------------