Page.java 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package com.tzld.piaoquan.featurestools.util.page;
  2. import java.util.List;
  3. public class Page<T> {
  4. public static final String DEFAULT_PAGE_SIZE = "20";
  5. public static final String DEFAULT_CURRENT_PAGE = "1";
  6. private int currentPage = Integer.valueOf(DEFAULT_CURRENT_PAGE);
  7. private int totalSize;
  8. private int pageSize = Integer.valueOf(DEFAULT_PAGE_SIZE);
  9. private List<T> objs;
  10. private T obj;
  11. public Page() {
  12. }
  13. public Page(int currentPage) {
  14. this.currentPage = currentPage;
  15. }
  16. public Page(int currentPage, int pageSize) {
  17. setCurrentPage(currentPage);
  18. setPageSize(pageSize);
  19. }
  20. public int getNextPage() {
  21. return currentPage == getTotalPage() ? currentPage : currentPage + 1;
  22. }
  23. public int getPrePage() {
  24. return currentPage > 1 ? currentPage - 1 : 1;
  25. }
  26. public int getOffset() {
  27. return getCurPageFirstRecNum() - 1;
  28. }
  29. public int getCurPageFirstRecNum() {
  30. return (getCurrentPage() - 1) * pageSize + 1;
  31. }
  32. public int getCurPageLastRecNum() {
  33. return getCurrentPage() * pageSize;
  34. }
  35. public int getTotalPage() {
  36. int t = totalSize % pageSize > 0 ? totalSize / pageSize + 1 : totalSize / pageSize;
  37. if (t <= 0) {
  38. t = 1;
  39. }
  40. return t;
  41. }
  42. public void setObjs(List<T> objs) {
  43. this.objs = objs;
  44. }
  45. public List<T> getObjs() {
  46. return objs;
  47. }
  48. public int getCurrentPage() {
  49. return currentPage;
  50. }
  51. public void setCurrentPage(int currentPage) {
  52. this.currentPage = currentPage;
  53. }
  54. public int getTotalSize() {
  55. return totalSize;
  56. }
  57. public void setTotalSize(int totalSize) {
  58. this.totalSize = totalSize;
  59. }
  60. public int getPageSize() {
  61. return pageSize;
  62. }
  63. public void setPageSize(int pageSize) {
  64. if (pageSize > 0) {
  65. this.pageSize = pageSize;
  66. }
  67. }
  68. public boolean containData() {
  69. return getTotalSize() > 0;
  70. }
  71. @Override
  72. public String toString() {
  73. return "Page [currentPage=" + getCurrentPage() + ", totalSize=" + getTotalSize() + ", pageSize=" + getPageSize()
  74. + "]";
  75. }
  76. public T getObj() {
  77. return obj;
  78. }
  79. public void setObj(T obj) {
  80. this.obj = obj;
  81. }
  82. }