|
@@ -9,82 +9,61 @@ import java.util.List;
|
|
* @author: bianlanzhou
|
|
* @author: bianlanzhou
|
|
* @create: 2024-08-05 17:20
|
|
* @create: 2024-08-05 17:20
|
|
* @description: copy from https://github.com/alibaba/COLA/tree/COLA4.3.2?tab=readme-ov-file
|
|
* @description: copy from https://github.com/alibaba/COLA/tree/COLA4.3.2?tab=readme-ov-file
|
|
|
|
+ * 适配了pageHelper
|
|
**/
|
|
**/
|
|
public class PageResponse<T> extends Response {
|
|
public class PageResponse<T> extends Response {
|
|
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
private static final long serialVersionUID = 1L;
|
|
-
|
|
|
|
- private int totalCount = 0;
|
|
|
|
-
|
|
|
|
- private int pageSize = 1;
|
|
|
|
-
|
|
|
|
- private int pageIndex = 1;
|
|
|
|
-
|
|
|
|
|
|
+ private long totalCount = 0L;
|
|
|
|
+ private long pageSize = 1L;
|
|
|
|
+ private long pageIndex = 1L;
|
|
private Collection<T> data;
|
|
private Collection<T> data;
|
|
|
|
|
|
- public int getTotalCount() {
|
|
|
|
- return totalCount;
|
|
|
|
|
|
+ public PageResponse() {
|
|
}
|
|
}
|
|
|
|
|
|
- public void setTotalCount(int totalCount) {
|
|
|
|
|
|
+ public long getTotalCount() {
|
|
|
|
+ return this.totalCount;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void setTotalCount(long totalCount) {
|
|
this.totalCount = totalCount;
|
|
this.totalCount = totalCount;
|
|
}
|
|
}
|
|
|
|
|
|
- public int getPageSize() {
|
|
|
|
- if (pageSize < 1) {
|
|
|
|
- return 1;
|
|
|
|
- }
|
|
|
|
- return pageSize;
|
|
|
|
|
|
+ public long getPageSize() {
|
|
|
|
+ return Math.max(this.pageSize, 1L);
|
|
}
|
|
}
|
|
|
|
|
|
- public void setPageSize(int pageSize) {
|
|
|
|
- if (pageSize < 1) {
|
|
|
|
- this.pageSize = 1;
|
|
|
|
- } else {
|
|
|
|
- this.pageSize = pageSize;
|
|
|
|
- }
|
|
|
|
|
|
+ public void setPageSize(long pageSize) {
|
|
|
|
+ this.pageSize = Math.max(pageSize, 1L);
|
|
}
|
|
}
|
|
|
|
|
|
- public int getPageIndex() {
|
|
|
|
- if (pageIndex < 1) {
|
|
|
|
- return 1;
|
|
|
|
- }
|
|
|
|
- return pageIndex;
|
|
|
|
|
|
+ public long getPageIndex() {
|
|
|
|
+ return Math.max(this.pageIndex, 1L);
|
|
}
|
|
}
|
|
|
|
|
|
- public void setPageIndex(int pageIndex) {
|
|
|
|
- if (pageIndex < 1) {
|
|
|
|
- this.pageIndex = 1;
|
|
|
|
- } else {
|
|
|
|
- this.pageIndex = pageIndex;
|
|
|
|
- }
|
|
|
|
|
|
+ public void setPageIndex(long pageIndex) {
|
|
|
|
+ this.pageIndex = Math.max(pageIndex, 1L);
|
|
}
|
|
}
|
|
|
|
|
|
public List<T> getData() {
|
|
public List<T> getData() {
|
|
- if (null == data) {
|
|
|
|
- return Collections.emptyList();
|
|
|
|
- }
|
|
|
|
- if (data instanceof List) {
|
|
|
|
- return (List<T>) data;
|
|
|
|
- }
|
|
|
|
- return new ArrayList<>(data);
|
|
|
|
|
|
+ return (List)(this.data == null ? Collections.emptyList() : new ArrayList(this.data));
|
|
}
|
|
}
|
|
|
|
|
|
public void setData(Collection<T> data) {
|
|
public void setData(Collection<T> data) {
|
|
this.data = data;
|
|
this.data = data;
|
|
}
|
|
}
|
|
|
|
|
|
- public int getTotalPages() {
|
|
|
|
- return this.totalCount % this.pageSize == 0 ? this.totalCount
|
|
|
|
- / this.pageSize : (this.totalCount / this.pageSize) + 1;
|
|
|
|
|
|
+ public long getTotalPages() {
|
|
|
|
+ return this.totalCount % this.pageSize == 0L ? this.totalCount / this.pageSize : this.totalCount / this.pageSize + 1L;
|
|
}
|
|
}
|
|
|
|
|
|
public boolean isEmpty() {
|
|
public boolean isEmpty() {
|
|
- return data == null || data.isEmpty();
|
|
|
|
|
|
+ return this.data == null || this.data.size() == 0;
|
|
}
|
|
}
|
|
|
|
|
|
public boolean isNotEmpty() {
|
|
public boolean isNotEmpty() {
|
|
- return !isEmpty();
|
|
|
|
|
|
+ return !this.isEmpty();
|
|
}
|
|
}
|
|
|
|
|
|
public static PageResponse buildSuccess() {
|
|
public static PageResponse buildSuccess() {
|
|
@@ -101,18 +80,18 @@ public class PageResponse<T> extends Response {
|
|
return response;
|
|
return response;
|
|
}
|
|
}
|
|
|
|
|
|
- public static <T> PageResponse<T> of(int pageSize, int pageIndex) {
|
|
|
|
- PageResponse<T> response = new PageResponse<>();
|
|
|
|
|
|
+ public static <T> PageResponse<T> of(long pageSize, long pageIndex) {
|
|
|
|
+ PageResponse<T> response = new PageResponse();
|
|
response.setSuccess(true);
|
|
response.setSuccess(true);
|
|
response.setData(Collections.emptyList());
|
|
response.setData(Collections.emptyList());
|
|
- response.setTotalCount(0);
|
|
|
|
|
|
+ response.setTotalCount(0L);
|
|
response.setPageSize(pageSize);
|
|
response.setPageSize(pageSize);
|
|
response.setPageIndex(pageIndex);
|
|
response.setPageIndex(pageIndex);
|
|
return response;
|
|
return response;
|
|
}
|
|
}
|
|
|
|
|
|
- public static <T> PageResponse<T> of(Collection<T> data, int totalCount, int pageSize, int pageIndex) {
|
|
|
|
- PageResponse<T> response = new PageResponse<>();
|
|
|
|
|
|
+ public static <T> PageResponse<T> of(Collection<T> data, long totalCount, long pageSize, long pageIndex) {
|
|
|
|
+ PageResponse<T> response = new PageResponse();
|
|
response.setSuccess(true);
|
|
response.setSuccess(true);
|
|
response.setData(data);
|
|
response.setData(data);
|
|
response.setTotalCount(totalCount);
|
|
response.setTotalCount(totalCount);
|
|
@@ -120,5 +99,4 @@ public class PageResponse<T> extends Response {
|
|
response.setPageIndex(pageIndex);
|
|
response.setPageIndex(pageIndex);
|
|
return response;
|
|
return response;
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|