Skip to content

Commit

Permalink
fix: 修复分页查询条件默认值未生效的问题
Browse files Browse the repository at this point in the history
Spring MVC 对于对象型参数的属性赋值,如果属性值为 null 则不会调用其对应 set 方法,所以在 set
方法中添加默认处理逻辑无效
  • Loading branch information
Charles7c committed Apr 8, 2023
1 parent 18c54a7 commit 2d2a7e7
Showing 1 changed file with 6 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,24 @@
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 分页条件
Expand All @@ -92,12 +86,4 @@ public <T> IPage<T> toPage() {
}
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;
}
}

0 comments on commit 2d2a7e7

Please sign in to comment.