Merge pull request #367 from leoluo0818/main

添加分页时每页显示的数据数量最大限制
This commit is contained in:
Michael Yang 2024-07-22 10:12:34 +08:00 committed by GitHub
commit 82be5d4a69
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 1 deletions

View File

@ -83,6 +83,11 @@ public class FlexGlobalConfig {
*/ */
private int defaultPageSize = 10; private int defaultPageSize = 10;
/**
* 分页查询时默认每页显示的数据数量最大限制
*/
private int defaultMaxPageSize = Long.MAX_VALUE;
/** /**
* 默认的 Relation 注解查询深度 * 默认的 Relation 注解查询深度
@ -278,6 +283,14 @@ public class FlexGlobalConfig {
this.defaultPageSize = defaultPageSize; this.defaultPageSize = defaultPageSize;
} }
public int getDefaultMaxPageSize() {
return defaultMaxPageSize;
}
public void setDefaultMaxPageSize(int defaultMaxPageSize) {
this.defaultMaxPageSize = defaultMaxPageSize;
}
public int getDefaultRelationQueryDepth() { public int getDefaultRelationQueryDepth() {
return defaultRelationQueryDepth; return defaultRelationQueryDepth;
} }

View File

@ -51,6 +51,11 @@ public class Page<T> implements Serializable {
*/ */
private long pageSize = FlexGlobalConfig.getDefaultConfig().getDefaultPageSize(); private long pageSize = FlexGlobalConfig.getDefaultConfig().getDefaultPageSize();
/**
* 每页数据数量最大限制
*/
private long maxPageSize = FlexGlobalConfig.getDefaultConfig().getDefaultMaxPageSize();
/** /**
* 总页数 * 总页数
*/ */
@ -196,7 +201,7 @@ public class Page<T> implements Serializable {
if (pageSize <= 0) { if (pageSize <= 0) {
throw new IllegalArgumentException("pageSize must greater than 0current value is: " + pageSize); throw new IllegalArgumentException("pageSize must greater than 0current value is: " + pageSize);
} }
this.pageSize = pageSize; this.pageSize = Math.min(pageSize, maxPageSize);
this.calcTotalPage(); this.calcTotalPage();
} }