| | |
| | | package com.ruoyi.framework.config; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.DbType; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.ParameterUtils; |
| | | 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 com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor; |
| | | import com.ruoyi.common.handler.CustomTenantLineHandler; |
| | | import org.apache.ibatis.executor.Executor; |
| | | import org.apache.ibatis.mapping.BoundSql; |
| | | import org.apache.ibatis.mapping.MappedStatement; |
| | | import org.apache.ibatis.session.ResultHandler; |
| | | import org.apache.ibatis.session.RowBounds; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.transaction.annotation.EnableTransactionManagement; |
| | | |
| | | import java.sql.SQLException; |
| | | |
| | | /** |
| | | * Mybatis Plus 配置 |
| | |
| | | /** |
| | | * 分页插件,自动识别数据库类型 https://baomidou.com/guide/interceptor-pagination.html |
| | | */ |
| | | public PaginationInnerInterceptor paginationInnerInterceptor() |
| | | { |
| | | PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(); |
| | | // 设置数据库类型为mysql |
| | | paginationInnerInterceptor.setDbType(DbType.MYSQL); |
| | | // 设置最大单页限制数量,默认 500 条,-1 不受限制 |
| | | paginationInnerInterceptor.setMaxLimit(-1L); |
| | | return paginationInnerInterceptor; |
| | | // public PaginationInnerInterceptor paginationInnerInterceptor() |
| | | // { |
| | | // PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(); |
| | | // // 设置数据库类型为mysql |
| | | // paginationInnerInterceptor.setDbType(DbType.MYSQL); |
| | | // // 设置最大单页限制数量,默认 500 条,-1 不受限制 |
| | | // paginationInnerInterceptor.setMaxLimit(-1L); |
| | | // return paginationInnerInterceptor; |
| | | // } |
| | | |
| | | public PaginationInnerInterceptor paginationInnerInterceptor() { |
| | | PaginationInnerInterceptor interceptor = new PaginationInnerInterceptor(DbType.MYSQL) { |
| | | @Override |
| | | public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, |
| | | RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException { |
| | | IPage<?> page = ParameterUtils.findPage(parameter).orElse(null); |
| | | if (page != null && page.getSize() <= 0) { |
| | | // 当size<=0时,不进行分页 |
| | | return; |
| | | } |
| | | super.beforeQuery(executor, ms, parameter, rowBounds, resultHandler, boundSql); |
| | | } |
| | | }; |
| | | interceptor.setMaxLimit(1000L); // 建议设置合理的最大值 |
| | | return interceptor; |
| | | } |
| | | |
| | | /** |