分页代码

 Java代码 复制代码 收藏代码

  1. 分页类:
分页类:
Java代码 复制代码 收藏代码
  1. package com.zhao.page;
  2.  
  3. public class PageCut {
  4.  
  5. private int pageSize;
  6. private int countRecord;
  7. private int countPage;
  8. private int startIndex;
  9. private int endIndex;
  10. private int nowPage;
  11.  
  12. public PageCut(int pageSize, int countRecord, int nowPage) {
  13. super();
  14. this.pageSize = pageSize;
  15. this.countRecord = countRecord;
  16. this.nowPage = nowPage;
  17. getPaginationPage();
  18. }
  19.  
  20. private void getPaginationPage() {
  21. // 计算开始索引
  22. this.startIndex = (nowPage - 1) * pageSize + 1;
  23. // 计算总页数
  24. this.countPage = (countRecord % pageSize == 0) ? (countRecord / pageSize)
  25. : (countRecord / pageSize + 1);
  26. this.endIndex = (nowPage * pageSize)>= countRecord ? countRecord:nowPage*pageSize;
  27. }
  28.  
  29. public int getPageSize() {
  30. return pageSize;
  31. }
  32.  
  33. public void setPageSize(int pageSize) {
  34. this.pageSize = pageSize;
  35. }
  36.  
  37. public int getCountRecord() {
  38. return countRecord;
  39. }
  40.  
  41. public void setCountRecord(int countRecord) {
  42. this.countRecord = countRecord;
  43. }
  44.  
  45. public int getCountPage() {
  46. return countPage;
  47. }
  48.  
  49. public void setCountPage(int countPage) {
  50. this.countPage = countPage;
  51. }
  52.  
  53. public int getStartIndex() {
  54. return startIndex;
  55. }
  56.  
  57. public void setStartIndex(int startIndex) {
  58. this.startIndex = startIndex;
  59. }
  60.  
  61. public int getNowPage() {
  62. return nowPage;
  63. }
  64.  
  65. public void setNowPage(int nowPage) {
  66. this.nowPage = nowPage;
  67. }
  68.  
  69. public int getEndIndex() {
  70. return endIndex;
  71. }
  72.  
  73. public void setEndIndex(int endIndex) {
  74. this.endIndex = endIndex;
  75. }   

你可能感兴趣的:(2)