io.github.dengchen2020.core.support.model.PageParam Maven / Gradle / Ivy
package io.github.dengchen2020.core.support.model;
import jakarta.validation.constraints.Min;
import org.hibernate.validator.constraints.Range;
import java.io.Serial;
import java.io.Serializable;
/**
* 分页查询条件
*
* @author dengchen
* @since 2019/2/26 10:17
*/
public class PageParam implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
public static PageParam of(int page, int size){
PageParam param = new PageParam();
param.setPage(page);
param.setSize(size);
return param;
}
public static PageParam of(int page, int size, boolean selectCount){
PageParam param = of(page, size);
param.setSelectCount(selectCount);
return param;
}
/**
* 页码,值>0,默认1
*/
@Min(value = 1)
private Integer page;
/**
* 每页数据条数,1-100,默认10;size=0,没有列表信息,只查总数total
*/
@Range(min = 0, max = 100)
private Integer size = 10;
private boolean selectCount = true;
public Integer getSize() {
return size == null ? 10 : size;
}
public Integer getPage() {
return (page != null && page > 0) ? page : 1;
}
public long getOffset() {
return (long) (getPage() - 1) * getSize();
}
public void setPage(Integer page) {
this.page = page;
}
public void setSize(Integer size) {
this.size = size;
}
public boolean isSelectCount() {
return selectCount;
}
public void setSelectCount(boolean selectCount) {
this.selectCount = selectCount;
}
}