fix
This commit is contained in:
parent
eee546fcc4
commit
6419f88c63
@ -20,6 +20,11 @@
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
|
||||
</dependency>
|
||||
<!-- 分页插件 -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-jsqlparser</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>dynamic-datasource-spring-boot3-starter</artifactId>
|
||||
@ -36,4 +41,4 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
|
||||
@ -2,7 +2,9 @@ package com.agileboot.common.mybatis.config;
|
||||
|
||||
import com.agileboot.common.core.factory.YmlPropertySourceFactory;
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@ -16,8 +18,14 @@ public class MybatisPlusConfiguration {
|
||||
@Bean
|
||||
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||
// 分页插件 自动识别数据库类型
|
||||
PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
|
||||
paginationInnerInterceptor.setOverflow(true); // 超出总页数后回到首页
|
||||
interceptor.addInnerInterceptor(paginationInnerInterceptor);
|
||||
// 乐观锁插件
|
||||
interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
|
||||
// 阻止恶意的全表更新删除
|
||||
interceptor.addInnerInterceptor(new BlockAttackInnerInterceptor());
|
||||
return interceptor;
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
package com.agileboot.common.mybatis.core.page;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.agileboot.common.core.exception.ServiceException;
|
||||
@ -8,8 +7,10 @@ import com.agileboot.common.core.utils.sql.SqlUtil;
|
||||
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import jakarta.validation.constraints.Max;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.Serial;
|
||||
@ -29,40 +30,37 @@ public class PageQuery implements Serializable {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static final int MAX_PAGE_NUM = 200; // 最大分页页数
|
||||
public static final int MAX_PAGE_SIZE = 500; // 单页最大大小
|
||||
public static final int DEFAULT_PAGE_NUM = 1; // 默认分页页数
|
||||
public static final int DEFAULT_PAGE_SIZE = 10; // 默认分页大小
|
||||
|
||||
/**
|
||||
* 分页大小
|
||||
*/
|
||||
private Integer pageSize;
|
||||
@Max(MAX_PAGE_SIZE)
|
||||
protected Integer pageSize;
|
||||
|
||||
/**
|
||||
* 当前页数
|
||||
*/
|
||||
private Integer pageNum;
|
||||
@Max(MAX_PAGE_NUM)
|
||||
protected Integer pageNum;
|
||||
|
||||
/**
|
||||
* 排序列
|
||||
*/
|
||||
private String orderByColumn;
|
||||
protected String orderByColumn;
|
||||
|
||||
/**
|
||||
* 排序的方向desc或者asc
|
||||
*/
|
||||
private String isAsc;
|
||||
|
||||
/**
|
||||
* 当前记录起始索引 默认值
|
||||
*/
|
||||
public static final int DEFAULT_PAGE_NUM = 1;
|
||||
|
||||
/**
|
||||
* 每页显示记录数 默认值 默认查全部
|
||||
*/
|
||||
public static final int DEFAULT_PAGE_SIZE = Integer.MAX_VALUE;
|
||||
protected String isAsc;
|
||||
|
||||
/**
|
||||
* 构建分页对象
|
||||
*/
|
||||
public <T> Page<T> build() {
|
||||
public <T> Page<T> buildPage() {
|
||||
Integer pageNum = ObjectUtil.defaultIfNull(getPageNum(), DEFAULT_PAGE_NUM);
|
||||
Integer pageSize = ObjectUtil.defaultIfNull(getPageSize(), DEFAULT_PAGE_SIZE);
|
||||
if (pageNum <= 0) {
|
||||
@ -70,7 +68,7 @@ public class PageQuery implements Serializable {
|
||||
}
|
||||
Page<T> page = new Page<>(pageNum, pageSize);
|
||||
List<OrderItem> orderItems = buildOrderItem();
|
||||
if (CollUtil.isNotEmpty(orderItems)) {
|
||||
if (CollectionUtils.isNotEmpty(orderItems)) {
|
||||
page.addOrder(orderItems);
|
||||
}
|
||||
return page;
|
||||
|
||||
@ -0,0 +1,69 @@
|
||||
package com.agileboot.common.mybatis.core.page;
|
||||
|
||||
import cn.hutool.http.HttpStatus;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 分页模型类
|
||||
*
|
||||
* @author valarchie
|
||||
*/
|
||||
@Data
|
||||
public class PageR<T> {
|
||||
private List<T> rows; // 列表数据
|
||||
private Long total; // 总记录数
|
||||
private Long current; // 当前页数
|
||||
private Long size; // 每页记录数
|
||||
private Long pages; // 总页数
|
||||
|
||||
private int code;
|
||||
private String msg;
|
||||
|
||||
public static <T> PageR<T> build() {
|
||||
PageR<T> r = new PageR<>();
|
||||
r.setCode(HttpStatus.HTTP_OK);
|
||||
r.setMsg("查询成功");
|
||||
r.setTotal(0L);
|
||||
r.setPages(0L);
|
||||
r.setCurrent(0L);
|
||||
r.setSize(0L);
|
||||
return r;
|
||||
}
|
||||
|
||||
public static <T> PageR<T> build(List<T> list) {
|
||||
PageR<T> r = new PageR<>();
|
||||
r.setCode(HttpStatus.HTTP_OK);
|
||||
r.setMsg("查询成功");
|
||||
r.setRows(list);
|
||||
r.setTotal((long) list.size());
|
||||
return r;
|
||||
}
|
||||
|
||||
public static <T> PageR<T> build(IPage<T> page) {
|
||||
PageR<T> r = PageR.build();
|
||||
r.setRows(page.getRecords());
|
||||
r.setSize(page.getSize());
|
||||
r.setPages(page.getPages());
|
||||
r.setTotal(page.getTotal());
|
||||
r.setCurrent(page.getCurrent());
|
||||
return r;
|
||||
}
|
||||
|
||||
public static <T> PageR<T> build(IPage<?> page, List<T> list) {
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
return PageR.build();
|
||||
}
|
||||
PageR<T> r = PageR.build();
|
||||
r.setRows(list);
|
||||
r.setSize(page.getSize());
|
||||
r.setPages(page.getPages());
|
||||
r.setTotal(page.getTotal());
|
||||
r.setCurrent(page.getCurrent());
|
||||
return r;
|
||||
}
|
||||
|
||||
}
|
||||
@ -18,7 +18,7 @@ mybatis-plus:
|
||||
# 更详细的日志输出 会有性能损耗 org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
# 关闭日志记录 (可单纯使用 p6spy 分析) org.apache.ibatis.logging.nologging.NoLoggingImpl
|
||||
# 默认日志输出 org.apache.ibatis.logging.slf4j.Slf4jImpl
|
||||
logImpl: org.apache.ibatis.logging.slf4j.Slf4jImpl
|
||||
logImpl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
global-config:
|
||||
banner: true # 是否打印 Logo banner
|
||||
dbConfig:
|
||||
|
||||
5
pom.xml
5
pom.xml
@ -108,6 +108,11 @@
|
||||
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
|
||||
<version>${mybatis-plus.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-jsqlparser</artifactId>
|
||||
<version>${mybatis-plus.version}</version>
|
||||
</dependency>
|
||||
<!-- <!– mybatis plus 代码生成器依赖 –>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.baomidou</groupId>-->
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user