赞
踩
目录
mybatis-plus会自动生成CURD的一些基础,方便快速开发使用,若依框架本身使用的是mybaits,打算将若依框架升级mybaits-plus.
MyBatis-Plus (opens new window)(简称 MP)是一个 MyBatis (opens new window)的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化开发、提高效率而生。
项目根程序下的pom.xml文件修改
- <!-- mybatis plus -->
- <dependency>
- <groupId>com.baomidou</groupId>
- <artifactId>mybatis-plus-boot-starter</artifactId>
- <version>${mybatis-plus.version}</version>
- </dependency>
-
- <!-- pagehelper 分页插件 -->
- <dependency>
- <groupId>com.github.pagehelper</groupId>
- <artifactId>pagehelper-spring-boot-starter</artifactId>
- <version>${pagehelper.boot.version}</version>
- <exclusions>
- <exclusion>
- <groupId>org.mybatis</groupId>
- <artifactId>mybatis</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
子模块 ruoyi-common下的pom.xml
- <!-- mybatis-plus -->
- <dependency>
- <groupId>com.baomidou</groupId>
- <artifactId>mybatis-plus-boot-starter</artifactId>
- </dependency>
ruoyi-admin子模块下的yml配置文件
# MyBatis #mybatis: # # 搜索指定包别名 # typeAliasesPackage: com.ruoyi.**.domain # # 配置mapper的扫描,找到所有的mapper.xml映射文件 # mapperLocations: classpath*:mapper/**/*Mapper.xml # # 加载全局的配置文件 # configLocation: classpath:mybatis/mybatis-config.xml # MyBatis Plus配置 mybatis-plus: # 搜索指定包别名 typeAliasesPackage: com.adlot.**.domain # 配置mapper的扫描,找到所有的mapper.xml映射文件 mapperLocations: classpath*:mapper/**/*Mapper.xml # 加载全局的配置文件 configLocation: classpath:mybatis/mybatis-config.xml
屏蔽掉ruoyi-framework下MyBaitsConfig.java的代码
-
- import com.adlot.framework.handler.CustomTenantLineHandler;
- import com.baomidou.mybatisplus.annotation.DbType;
- 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 org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.transaction.annotation.EnableTransactionManagement;
-
- /**
- * Mybatis Plus 配置
- *
- * @author ruoyi
- */
- @EnableTransactionManagement(proxyTargetClass = true)
- @Configuration
- public class MybatisPlusConfig
- {
-
- @Autowired
- private CustomTenantLineHandler customTenantLineHandler;
- @Bean
- public MybatisPlusInterceptor mybatisPlusInterceptor()
- {
- MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
- // 多租户插件(注意:这个一定要放在最上面)
- //interceptor.addInnerInterceptor(new TenantLineInnerInterceptor(customTenantLineHandler));
- // 分页插件
- interceptor.addInnerInterceptor(paginationInnerInterceptor());
- // 乐观锁插件
- interceptor.addInnerInterceptor(optimisticLockerInnerInterceptor());
- // 阻断插件
- interceptor.addInnerInterceptor(blockAttackInnerInterceptor());
- return interceptor;
- }
-
- /**
- * 分页插件,自动识别数据库类型 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;
- }
-
- /**
- * 乐观锁插件 https://baomidou.com/guide/interceptor-optimistic-locker.html
- */
- public OptimisticLockerInnerInterceptor optimisticLockerInnerInterceptor()
- {
- return new OptimisticLockerInnerInterceptor();
- }
-
- /**
- * 如果是对全表的删除或更新操作,就会终止该操作 https://baomidou.com/guide/interceptor-block-attack.html
- */
- public BlockAttackInnerInterceptor blockAttackInnerInterceptor()
- {
- return new BlockAttackInnerInterceptor();
- }
- }
就这样可以了
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。