| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- package com.uas.search.constant.model;
- import org.springframework.data.domain.Pageable;
- import org.springframework.data.domain.Sort;
- import com.alibaba.fastjson.JSONObject;
- public class PageInfo implements Pageable {
- private int pageNumber;
- private int pageSize;
- private int offset;
- private Sort sort;
- public PageInfo() {
- }
- public PageInfo(String jsonPageParams) {
- PageParams params = JSONObject.parseObject(jsonPageParams, PageParams.class);
- getPageInfo(params);
- }
- public PageInfo(PageParams params) {
- getPageInfo(params);
- }
- public PageInfo(PageParams params,Sort sort) {
- getPageInfo(params);
- this.sort = sort;
- }
- private void getPageInfo(PageParams params) {
- this.pageSize = params.getSize();
- if (this.pageSize == 0) {
- this.pageSize = 5;
- }
- if (this.pageSize > 1000) {
- throw new IllegalArgumentException("页面大小不可超过1000");
- }
- this.pageNumber = params.getPage();
- if (this.pageNumber == 0) {
- this.pageNumber = 1;
- }
- this.offset = (this.pageSize * (this.pageNumber - 1));
- }
- public PageInfo(int pageNumber, int pageSize) {
- this.pageNumber = pageNumber;
- this.pageSize = pageSize;
- this.offset = (this.pageSize * (this.pageNumber - 1));
- }
- public PageInfo(int pageNumber, int pageSize, int offset) {
- this.pageNumber = pageNumber;
- this.pageSize = pageSize;
- this.offset = offset;
- }
- public int getPageNumber() {
- return this.pageNumber;
- }
- public int getPageSize() {
- return this.pageSize;
- }
- public int getOffset() {
- return this.offset;
- }
- public Sort getSort() {
- return this.sort;
- }
- public void setPageNumber(int pageNumber) {
- this.pageNumber = pageNumber;
- }
- public void setPageSize(int pageSize) {
- this.pageSize = pageSize;
- }
- public void setOffset(int offset) {
- this.offset = offset;
- }
- public void setSort(Sort sort) {
- this.sort = sort;
- }
- public Pageable next() {
- return null;
- }
- public Pageable previousOrFirst() {
- return null;
- }
- public Pageable first() {
- return null;
- }
- public boolean hasPrevious() {
- return false;
- }
- }
|