PageVo.java 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package com.example.common;
  2. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  3. import com.github.pagehelper.PageInfo;
  4. import io.swagger.v3.oas.annotations.media.Schema;
  5. import lombok.Data;
  6. import java.util.List;
  7. /**
  8. * 分页返回对象
  9. */
  10. @Data
  11. public class PageVo<T> {
  12. @Schema(description = "总记录数")
  13. private Long totalCount;
  14. @Schema(description = "每页记录数")
  15. private Long pageSize;
  16. @Schema(description = "总页数")
  17. private Long totalPage;
  18. @Schema(description = "当前页数")
  19. private Long currPage;
  20. @Schema(description = "列表数据")
  21. private List<T> list;
  22. public PageVo(List<T> list, Page page) {
  23. this.list = list;
  24. this.totalCount = page.getTotal();
  25. this.pageSize = page.getSize();
  26. this.currPage = page.getCurrent();
  27. this.totalPage = page.getPages();
  28. }
  29. /**
  30. * 分页
  31. *
  32. * @param list 列表数据
  33. * @param totalCount 总记录数
  34. * @param pageSize 每页记录数
  35. * @param currPage 当前页数
  36. */
  37. public PageVo(List<T> list, int totalCount, int pageSize, int currPage) {
  38. this.list = list;
  39. this.totalCount = (long) totalCount;
  40. this.pageSize = (long) pageSize;
  41. this.currPage = (long) currPage;
  42. this.totalPage = (long) Math.ceil((double) totalCount / pageSize);
  43. }
  44. public PageVo(PageInfo pageInfo) {
  45. this.list = pageInfo.getList();
  46. this.totalCount = pageInfo.getTotal();
  47. this.pageSize = (long) pageInfo.getPageSize();
  48. this.currPage = (long) pageInfo.getPageNum();
  49. this.totalPage = (long) pageInfo.getPages();
  50. }
  51. public PageVo(List<T> list) {
  52. this.list = list;
  53. }
  54. }