Skip to content

Commit 2d2a7e7

Browse files
committed
fix: 修复分页查询条件默认值未生效的问题
Spring MVC 对于对象型参数的属性赋值,如果属性值为 null 则不会调用其对应 set 方法,所以在 set 方法中添加默认处理逻辑无效
1 parent 18c54a7 commit 2d2a7e7

File tree

1 file changed

+6
-20
lines changed
  • continew-admin-common/src/main/java/top/charles7c/cnadmin/common/model/query

1 file changed

+6
-20
lines changed

continew-admin-common/src/main/java/top/charles7c/cnadmin/common/model/query/PageQuery.java

+6-20
Original file line numberDiff line numberDiff line change
@@ -47,30 +47,24 @@
4747
public class PageQuery extends SortQuery {
4848

4949
private static final long serialVersionUID = 1L;
50+
/** 默认页码:1 */
51+
private static final int DEFAULT_PAGE = 1;
52+
/** 默认每页条数:10 */
53+
private static final int DEFAULT_SIZE = 10;
5054

5155
/**
5256
* 页码
5357
*/
5458
@Schema(description = "页码")
5559
@Min(value = 1, message = "页码最小值为 {value}")
56-
private Integer page;
60+
private Integer page = DEFAULT_PAGE;
5761

5862
/**
5963
* 每页条数
6064
*/
6165
@Schema(description = "每页条数")
6266
@Range(min = 1, max = 1000, message = "每页条数(取值范围 {min}-{max})")
63-
private Integer size;
64-
65-
/** 默认页码:1 */
66-
private static final int DEFAULT_PAGE = 1;
67-
/** 默认每页条数:10 */
68-
private static final int DEFAULT_SIZE = 10;
69-
70-
public PageQuery(Integer page, Integer size) {
71-
this.setPage(page);
72-
this.setSize(size);
73-
}
67+
private Integer size = DEFAULT_SIZE;
7468

7569
/**
7670
* 基于分页查询条件转换为 MyBatis Plus 分页条件
@@ -92,12 +86,4 @@ public <T> IPage<T> toPage() {
9286
}
9387
return mybatisPage;
9488
}
95-
96-
public void setPage(Integer page) {
97-
this.page = page == null ? DEFAULT_PAGE : page;
98-
}
99-
100-
public void setSize(Integer size) {
101-
this.size = size == null ? DEFAULT_SIZE : size;
102-
}
10389
}

0 commit comments

Comments
 (0)