update 分页合理化
This commit is contained in:
parent
1a695159e3
commit
6801490e3b
@ -36,6 +36,11 @@ public class PageUtils {
|
||||
*/
|
||||
public static final String IS_ASC = "isAsc";
|
||||
|
||||
/**
|
||||
* 分页参数合理化
|
||||
*/
|
||||
private static final String REASONABLE = "reasonable";
|
||||
|
||||
/**
|
||||
* 当前记录起始索引 默认值
|
||||
*/
|
||||
@ -46,6 +51,11 @@ public class PageUtils {
|
||||
*/
|
||||
public static final int DEFAULT_PAGE_SIZE = Integer.MAX_VALUE;
|
||||
|
||||
/**
|
||||
* 分页参数合理化 默认值
|
||||
*/
|
||||
private static final Boolean DEFAULT_REASONABLE = Boolean.TRUE;
|
||||
|
||||
/**
|
||||
* 构建 plus 分页对象
|
||||
* @param <T> domain 实体
|
||||
@ -57,6 +67,11 @@ public class PageUtils {
|
||||
Integer pageSize = ServletUtils.getParameterToInt(PAGE_SIZE, DEFAULT_PAGE_SIZE);
|
||||
String orderByColumn = ServletUtils.getParameter(ORDER_BY_COLUMN);
|
||||
String isAsc = ServletUtils.getParameter(IS_ASC);
|
||||
Boolean reasonable = ServletUtils.getParameterToBool(REASONABLE, DEFAULT_REASONABLE);
|
||||
//分页合理化,针对不合理的页码自动处理
|
||||
if (reasonable && pageNum <= 0) {
|
||||
pageNum = 1;
|
||||
}
|
||||
PagePlus<T, K> page = new PagePlus<>(pageNum, pageSize);
|
||||
if (StringUtils.isNotBlank(orderByColumn)) {
|
||||
String orderBy = SqlUtil.escapeOrderBySql(orderByColumn);
|
||||
@ -83,7 +98,12 @@ public class PageUtils {
|
||||
Integer pageSize = ServletUtils.getParameterToInt(PAGE_SIZE, DEFAULT_PAGE_SIZE);
|
||||
String orderByColumn = ServletUtils.getParameter(ORDER_BY_COLUMN, defaultOrderByColumn);
|
||||
String isAsc = ServletUtils.getParameter(IS_ASC, defaultIsAsc);
|
||||
// 兼容前端排序类型
|
||||
Boolean reasonable = ServletUtils.getParameterToBool(REASONABLE, DEFAULT_REASONABLE);
|
||||
//分页合理化,针对不合理的页码自动处理
|
||||
if (reasonable && pageNum <= 0) {
|
||||
pageNum = 1;
|
||||
}
|
||||
// 兼容前端排序类型
|
||||
if ("ascending".equals(isAsc)) {
|
||||
isAsc = "asc";
|
||||
} else if ("descending".equals(isAsc)) {
|
||||
|
@ -50,6 +50,8 @@ public class MybatisPlusConfig {
|
||||
paginationInnerInterceptor.setDbType(DbType.MYSQL);
|
||||
// 设置最大单页限制数量,默认 500 条,-1 不受限制
|
||||
paginationInnerInterceptor.setMaxLimit(-1L);
|
||||
// 分页合理化
|
||||
paginationInnerInterceptor.setOverflow(true);
|
||||
return paginationInnerInterceptor;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user