fix: 修复分页查询条件默认值未生效的问题
Spring MVC 对于对象型参数的属性赋值,如果属性值为 null 则不会调用其对应 set 方法,所以在 set 方法中添加默认处理逻辑无效
This commit is contained in:
parent
18c54a74fc
commit
2d2a7e7c8e
@ -47,30 +47,24 @@ import cn.hutool.core.util.StrUtil;
|
||||
public class PageQuery extends SortQuery {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
/** 默认页码:1 */
|
||||
private static final int DEFAULT_PAGE = 1;
|
||||
/** 默认每页条数:10 */
|
||||
private static final int DEFAULT_SIZE = 10;
|
||||
|
||||
/**
|
||||
* 页码
|
||||
*/
|
||||
@Schema(description = "页码")
|
||||
@Min(value = 1, message = "页码最小值为 {value}")
|
||||
private Integer page;
|
||||
private Integer page = DEFAULT_PAGE;
|
||||
|
||||
/**
|
||||
* 每页条数
|
||||
*/
|
||||
@Schema(description = "每页条数")
|
||||
@Range(min = 1, max = 1000, message = "每页条数(取值范围 {min}-{max})")
|
||||
private Integer size;
|
||||
|
||||
/** 默认页码:1 */
|
||||
private static final int DEFAULT_PAGE = 1;
|
||||
/** 默认每页条数:10 */
|
||||
private static final int DEFAULT_SIZE = 10;
|
||||
|
||||
public PageQuery(Integer page, Integer size) {
|
||||
this.setPage(page);
|
||||
this.setSize(size);
|
||||
}
|
||||
private Integer size = DEFAULT_SIZE;
|
||||
|
||||
/**
|
||||
* 基于分页查询条件转换为 MyBatis Plus 分页条件
|
||||
@ -92,12 +86,4 @@ public class PageQuery extends SortQuery {
|
||||
}
|
||||
return mybatisPage;
|
||||
}
|
||||
|
||||
public void setPage(Integer page) {
|
||||
this.page = page == null ? DEFAULT_PAGE : page;
|
||||
}
|
||||
|
||||
public void setSize(Integer size) {
|
||||
this.size = size == null ? DEFAULT_SIZE : size;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user