提交 5d14faa4 编写于 作者: M MicLng

Refactoring code. 复写Mybatis-Plus的分页插件,处理size=-1时查询全表问题

上级 d32d6c68
......@@ -19,9 +19,8 @@ package com.pig4cloud.pig.common.mybatis;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.pig4cloud.pig.common.mybatis.config.MybatisPlusMetaObjectHandler;
import com.pig4cloud.pig.common.mybatis.plugins.LimitInterceptor;
import com.pig4cloud.pig.common.mybatis.plugins.PigPaginationInnerInterceptor;
import com.pig4cloud.pig.common.mybatis.resolver.SqlFilterArgumentResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
......@@ -54,7 +53,7 @@ public class MybatisAutoConfiguration implements WebMvcConfigurer {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new LimitInterceptor(DbType.MYSQL));
interceptor.addInnerInterceptor(new PigPaginationInnerInterceptor(DbType.MYSQL));
return interceptor;
}
......
......@@ -25,7 +25,7 @@ import java.sql.SQLException;
*/
@Data
@NoArgsConstructor
public class LimitInterceptor extends PaginationInnerInterceptor {
public class PigPaginationInnerInterceptor extends PaginationInnerInterceptor {
/**
* 数据库类型
......@@ -41,16 +41,17 @@ public class LimitInterceptor extends PaginationInnerInterceptor {
*/
private IDialect dialect;
public LimitInterceptor(DbType dbType) {
public PigPaginationInnerInterceptor(DbType dbType) {
this.dbType = dbType;
}
public LimitInterceptor(IDialect dialect) {
public PigPaginationInnerInterceptor(IDialect dialect) {
this.dialect = dialect;
}
@Override
public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException {
public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds,
ResultHandler resultHandler, BoundSql boundSql) throws SQLException {
IPage<?> page = ParameterUtils.findPage(parameter).orElse(null);
// size 小于 0 直接设置为 0 , 即不查询任何数据
if (null != page && page.getSize() < 0) {
......@@ -58,4 +59,5 @@ public class LimitInterceptor extends PaginationInnerInterceptor {
}
super.beforeQuery(executor, ms, page, rowBounds, resultHandler, boundSql);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册