在使用若依(
RuoYi-vue
)时,发现若依用的是mybatis而不是mybatis-plus,所以为了保留原有代码生成器生成的方法,外加入mybaits-plus,故有了下面的内容:
1、ruoyi-admin的prom.xml中添加mybatis-plus依赖
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.1</version>
</dependency>
注意3.5.3版本不行,会报错
2、在ruoyi-framawork/main/java/config/MyBatisConfig中注释掉下面图片中的内容
3、在ruoyi-admin中的application.xml中注释掉mybatis配置并添加mybatis-plus配置
# MyBatis配置
#mybatis:
# # 搜索指定包别名
# typeAliasesPackage: com.ruoyi.**.domain
# # 配置mapper的扫描,找到所有的mapper.xml映射文件
# mapperLocations: classpath*:mapper/**/*Mapper.xml
# # 加载全局的配置文件
# configLocation: classpath:mybatis/mybatis-config.xml
# MyBatis-plus配置
mybatis-plus:
# 指定实体类所在包的路径,MyBatis-Plus 会自动扫描该路径下的实体类
typeAliasesPackage: com.ruoyi.**.domain
# 指定 Mapper 接口所在包的路径,MyBatis-Plus 会自动扫描该路径下的 Mapper 接口
mapperLocations: classpath*:mapper/**/*Mapper.xml
# 指定 MyBatis 全局配置文件的位置
# configLocation: classpath:mybatis/mybatis-config.xml
configuration:
#在映射实体或者属性时,将数据库中表名和字段名中的下划线去掉,按照驼峰命名法映射
map-underscore-to-camel-case: true
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
global-config:
db-config:
id-type: ASSIGN_ID
4、在ruoyi-admin的mapper层中新建一个**PlusMapper继承mybatis-plus的BaseMapper,以实体类AddressBook为例,AddressBookMapper为代码生成器自动生成的mapper,为了保存原来的mybatis定义的方法,并可以使用mybatis-plus的BaseMapper中的方法,这里新建一个AddressBookPlusMapper接口用于继承BaseMapper。
5、在service层中的AddressBook的接口IAddressBookService中继承mybatisplus的IService
6、大功告成,在若依中可以同时使用代码生成器生成的方法也可以使用mybatis-plus中的方法了,如下图,既可以使用系统生成的updateAddressBook(),也可以用mybatis-plus中的update()。
版权声明:本文为dgxl22原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。