PageUtils.java 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package com.chuanghai.ihotel.common.utils;
  2. import com.baomidou.mybatisplus.core.metadata.IPage;
  3. import lombok.NoArgsConstructor;
  4. import java.io.Serializable;
  5. import java.util.List;
  6. /**
  7. * 分页工具类
  8. * @author Mark sunlightcs@gmail.com
  9. */
  10. @NoArgsConstructor
  11. public class PageUtils<T> implements Serializable {
  12. private static final long serialVersionUID = 1L;
  13. /**
  14. * 总记录数
  15. */
  16. private int totalCount;
  17. /**
  18. * 每页记录数
  19. */
  20. private int pageSize;
  21. /**
  22. * 总页数
  23. */
  24. private int totalPage;
  25. /**
  26. * 当前页数
  27. */
  28. private int currPage;
  29. /**
  30. * 列表数据
  31. */
  32. private List<T> list;
  33. /**
  34. * 分页
  35. * @param list 列表数据
  36. * @param totalCount 总记录数
  37. * @param pageSize 每页记录数
  38. * @param currPage 当前页数
  39. */
  40. public PageUtils(List<T> list, int totalCount, int pageSize, int currPage) {
  41. this.list = list;
  42. this.totalCount = totalCount;
  43. this.pageSize = pageSize;
  44. this.currPage = currPage;
  45. this.totalPage = (int)Math.ceil((double)totalCount/pageSize);
  46. }
  47. /**
  48. * 分页
  49. */
  50. public PageUtils(IPage<T> page) {
  51. this.list = page.getRecords();
  52. this.totalCount = (int)page.getTotal();
  53. this.pageSize = (int)page.getSize();
  54. this.currPage = (int)page.getCurrent();
  55. this.totalPage = (int)page.getPages();
  56. }
  57. public int getTotalCount() {
  58. return totalCount;
  59. }
  60. public void setTotalCount(int totalCount) {
  61. this.totalCount = totalCount;
  62. }
  63. public int getPageSize() {
  64. return pageSize;
  65. }
  66. public void setPageSize(int pageSize) {
  67. this.pageSize = pageSize;
  68. }
  69. public int getTotalPage() {
  70. return totalPage;
  71. }
  72. public void setTotalPage(int totalPage) {
  73. this.totalPage = totalPage;
  74. }
  75. public int getCurrPage() {
  76. return currPage;
  77. }
  78. public void setCurrPage(int currPage) {
  79. this.currPage = currPage;
  80. }
  81. public List<?> getList() {
  82. return list;
  83. }
  84. public void setList(List<T> list) {
  85. this.list = list;
  86. }
  87. }