PageUtils.java 1.9 KB

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