PageUtils.java 1.8 KB

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