诺依集成mybatis换成mybatis-plus(完美解决)

总结分析:

问题1:mybatis与mybatis-plus能否共存?

经过将近一天的搜索发现,mybatis与mybatis-plus的sql工厂不通,mybatis是SqlSessionFactoryBean,而mybatis-plus是MybatisSqlSessionFactoryBean,所以一般最好是项目中使用一个最好,当然想要共存也可以,mybatis-plus的版本最好要高。

问题2:配置文件:当使用mybatis或者mybatis-plus时,配置文件只需要出现一个就行。

以下二选一!

mybatis配置文件:(就用诺依项目里的举例)

# 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:
  mapper-locations: classpath*:mapper/**/*Mapper.xml
#  config-location: classpath:mybatis/mybatis-config.xml
  #实体扫描,多个package用逗号或者分号分隔
  typeAliasesPackage: com.ruoyi.**.domain
  global-config:
    #数据库相关配置
    db-config:
      #主键类型  AUTO:"数据库ID自增", INPUT:"用户输入ID", ID_WORKER:"全局唯一ID (数字类型唯一ID)", UUID:"全局唯一ID UUID";
      id-type: AUTO
      logic-delete-value: -1
      logic-not-delete-value: 0
    banner: false
  #原生配置
  configuration:
    map-underscore-to-camel-case: true
    cache-enabled: false
    call-setters-on-nulls: true
    jdbc-type-for-null: 'null'

问题3: mybatis-plus的jar包

<dependency>
                <groupId>com.baomidou</groupId>
                <artifactId>mybatis-plus-boot-starter</artifactId>
                <version>${mybatisplus.version}</version>
            </dependency>

解决方法:

1. jar包引入:

在父依赖中设置mybatis-plus的版本依赖

引人父依赖模块,同时也在你扩展的模块引入即可。

同时在common模块引入mybatis-plus依赖。

2. 代码注释

原因:诺依中ruoyi-framework模块有对mybatis的配置类,而mybatis的sql工厂和mybatis-plus的sql工厂不同,否则会报以下错:(所以需要将这个配置类的相关代码注释即可)

mybatis-plus  Invalid bound statement (not found): com.ruoyi.file.mapper.UserfileMapper.selectCount

3. 修改配置:

打开admin模块的application.yml配置文件,将mybatis注释,改成mybatis-plus

同时需要注释掉:

因为yml中的Configuration和mybatis-config文件的configruation配置是不能共存的。否则会报以下错误

Property 'configuration' and 'configLocation' can not specified with together

欧克,集成完毕!!


版权声明:本文为qq_67801847原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。