PageInfo.java 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package com.uas.search.constant.model;
  2. import org.springframework.data.domain.Pageable;
  3. import org.springframework.data.domain.Sort;
  4. import com.alibaba.fastjson.JSONObject;
  5. public class PageInfo implements Pageable {
  6. private int pageNumber;
  7. private int pageSize;
  8. private int offset;
  9. private Sort sort;
  10. public PageInfo() {
  11. }
  12. public PageInfo(String jsonPageParams) {
  13. PageParams params = JSONObject.parseObject(jsonPageParams, PageParams.class);
  14. getPageInfo(params);
  15. }
  16. public PageInfo(PageParams params) {
  17. getPageInfo(params);
  18. }
  19. public PageInfo(PageParams params,Sort sort) {
  20. getPageInfo(params);
  21. this.sort = sort;
  22. }
  23. private void getPageInfo(PageParams params) {
  24. this.pageSize = params.getSize();
  25. if (this.pageSize == 0) {
  26. this.pageSize = 5;
  27. }
  28. if (this.pageSize > 1000) {
  29. throw new IllegalArgumentException("页面大小不可超过1000");
  30. }
  31. this.pageNumber = params.getPage();
  32. if (this.pageNumber == 0) {
  33. this.pageNumber = 1;
  34. }
  35. this.offset = (this.pageSize * (this.pageNumber - 1));
  36. }
  37. public PageInfo(int pageNumber, int pageSize) {
  38. this.pageNumber = pageNumber;
  39. this.pageSize = pageSize;
  40. this.offset = (this.pageSize * (this.pageNumber - 1));
  41. }
  42. public PageInfo(int pageNumber, int pageSize, int offset) {
  43. this.pageNumber = pageNumber;
  44. this.pageSize = pageSize;
  45. this.offset = offset;
  46. }
  47. public int getPageNumber() {
  48. return this.pageNumber;
  49. }
  50. public int getPageSize() {
  51. return this.pageSize;
  52. }
  53. public int getOffset() {
  54. return this.offset;
  55. }
  56. public Sort getSort() {
  57. return this.sort;
  58. }
  59. public void setPageNumber(int pageNumber) {
  60. this.pageNumber = pageNumber;
  61. }
  62. public void setPageSize(int pageSize) {
  63. this.pageSize = pageSize;
  64. }
  65. public void setOffset(int offset) {
  66. this.offset = offset;
  67. }
  68. public void setSort(Sort sort) {
  69. this.sort = sort;
  70. }
  71. public Pageable next() {
  72. return null;
  73. }
  74. public Pageable previousOrFirst() {
  75. return null;
  76. }
  77. public Pageable first() {
  78. return null;
  79. }
  80. public boolean hasPrevious() {
  81. return false;
  82. }
  83. }