柯桥增值式服务
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.4KB

  1. package com.ningdatech.kqapi.common.model;
  2. import lombok.Data;
  3. import lombok.NoArgsConstructor;
  4. import java.util.Collection;
  5. import java.util.Collections;
  6. /**
  7. * <p>
  8. * PageVo - 分页返回的包装对象
  9. * </p>
  10. *
  11. * @author WendyYang
  12. * @since 14:43 2022/9/29
  13. */
  14. @Data
  15. @NoArgsConstructor
  16. public class PageVo<T> {
  17. private Collection<T> records;
  18. private Long total;
  19. private Boolean hasNextPage;
  20. public PageVo(Collection<T> records, Boolean hasNextPage) {
  21. this.records = records;
  22. this.hasNextPage = hasNextPage;
  23. }
  24. public PageVo(Collection<T> records, Long total) {
  25. this.records = records;
  26. this.total = total;
  27. }
  28. public void setTotal(Long total) {
  29. this.total = total;
  30. }
  31. public static <T> PageVo<T> of(Collection<T> data, Long total) {
  32. return new PageVo<>(data, total);
  33. }
  34. public static <T> PageVo<T> of(Collection<T> data, Integer total) {
  35. return new PageVo<>(data, (long) total);
  36. }
  37. /**
  38. * 移动端无需展示总页码使用
  39. *
  40. * @param data 分页数据
  41. * @param hasNextPage 是否有下一页
  42. * @author WendyYang
  43. **/
  44. public static <T> PageVo<T> of(Collection<T> data, Boolean hasNextPage) {
  45. return new PageVo<>(data, hasNextPage);
  46. }
  47. public static <T> PageVo<T> empty() {
  48. return new PageVo<>(Collections.emptyList(), 0L);
  49. }
  50. }