CmMallPage.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. package com.caimei.entity;
  2. import java.io.Serializable;
  3. import java.util.Collection;
  4. import java.util.List;
  5. public class CmMallPage<T> implements Serializable{
  6. private static final long serialVersionUID = 1L;
  7. private int index;//当前页码
  8. private int pageSize;//每页大小
  9. private int totalRecord;//总记录数
  10. private int totalPage;//总页数?
  11. private boolean hasNextPage;//是否有后一页
  12. private boolean hasPreviousPage;//是否有前一页
  13. List<T> results;//查询结果
  14. public CmMallPage(List<T> list){
  15. if(list instanceof com.github.pagehelper.Page){
  16. com.github.pagehelper.Page<T> page = (com.github.pagehelper.Page<T>)list;
  17. this.index = page.getPageNum();
  18. this.pageSize = page.getPageSize();
  19. this.totalRecord = (int) page.getTotal();
  20. this.totalPage = page.getPages();
  21. setHasPreviousAndNext();
  22. this.results = page;
  23. }else if(list instanceof Collection){
  24. this.index = 1;
  25. this.pageSize = list.size();
  26. this.totalRecord = list.size();
  27. this.totalPage = 1;
  28. this.results = list;
  29. }
  30. }
  31. public CmMallPage(int index, int pageSize, int totalRecord, List<T> results) {
  32. super();
  33. this.index = index;
  34. this.pageSize = pageSize;
  35. this.totalRecord = totalRecord;
  36. this.totalPage = totalRecord % pageSize == 0 ? totalRecord/pageSize : totalRecord/pageSize+1;
  37. this.results = results;
  38. if(this.index<2){
  39. hasPreviousPage=false;
  40. }else{
  41. hasPreviousPage=true;
  42. }
  43. if(this.index<totalPage){
  44. hasNextPage = true;
  45. }else{
  46. hasNextPage = false;
  47. }
  48. }
  49. public CmMallPage(int index, int maxSize, int totalRecord, int totalPage,
  50. List<T> results) {
  51. super();
  52. this.index = index;
  53. this.pageSize = maxSize;
  54. this.totalRecord = totalRecord;
  55. this.totalPage = totalPage;
  56. this.results = results;
  57. if(this.index<2){
  58. hasPreviousPage=false;
  59. }else{
  60. hasPreviousPage=true;
  61. }
  62. if(this.index<totalPage){
  63. hasNextPage = true;
  64. }else{
  65. hasNextPage = false;
  66. }
  67. }
  68. public void setHasPreviousAndNext(){
  69. if(this.index<2){
  70. hasPreviousPage=false;
  71. }else{
  72. hasPreviousPage=true;
  73. }
  74. if(this.index<totalPage){
  75. hasNextPage = true;
  76. }else{
  77. hasNextPage = false;
  78. }
  79. }
  80. public CmMallPage() {
  81. super();
  82. }
  83. public int getIndex() {
  84. return index;
  85. }
  86. public void setIndex(int index) {
  87. this.index = index;
  88. }
  89. public int getPageSize() {
  90. return pageSize;
  91. }
  92. public void setPageSize(int maxSize) {
  93. this.pageSize = maxSize;
  94. }
  95. public int getTotalRecord() {
  96. return totalRecord;
  97. }
  98. public void setTotalRecord(int totalRecord) {
  99. this.totalRecord = totalRecord;
  100. }
  101. public int getTotalPage() {
  102. return totalPage;
  103. }
  104. public void setTotalPage(int totalPage) {
  105. this.totalPage = totalPage;
  106. }
  107. public List<T> getResults() {
  108. return results;
  109. }
  110. public void setResults(List<T> results) {
  111. this.results = results;
  112. }
  113. public boolean isHasNextPage() {
  114. return hasNextPage;
  115. }
  116. public void setHasNextPage(boolean hasNextPage) {
  117. this.hasNextPage = hasNextPage;
  118. }
  119. public boolean isHasPreviousPage() {
  120. return hasPreviousPage;
  121. }
  122. public void setHasPreviousPage(boolean hasPreviousPage) {
  123. this.hasPreviousPage = hasPreviousPage;
  124. }
  125. public int countTotalPage(){
  126. int total = totalRecord % pageSize == 0 ? totalRecord/pageSize : totalRecord/pageSize+1;
  127. this.setTotalPage(total);
  128. return total;
  129. }
  130. }