记录Springboot整合mybatis-plus中遇到的问题。
Springboot整合mybatis-plus
引入Maven依赖
POM文件
<!--添加父工程依赖-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.0</version>
<relativePath/>
</parent>
<!--添加mybatis-plus相关依赖-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.3.2</version>
</dependency>
application.yml
mybatis-plus:
mapper-locations: classpath:/mapper/*.xml
# 支持统配符 * 或者 ; 分割
typeEnumsPackage: com.wql.enums
configuration:
# 是否将sql打印到控制面板(该配置会将sql语句和查询的结果都打印到控制台)
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
global-config:
db-config:
logic-delete-field: delFlag # 全局逻辑删除的实体字段名(since 3.3.0,配置后可以忽略不配置步骤2)
logic-delete-value: 0 # 逻辑已删除值(默认为 1)
logic-not-delete-value: 1 # 逻辑未删除值(默认为 0)
id-type: auto
属性说明:
map-underscore-to-camel-case为true来开启驼峰功能,在mybatis-plus默认为开启状态
package com.baomidou.mybatisplus.core;
/**
* replace default Configuration class
* <p>Caratacus 2016/9/25 replace mapperRegistry</p>
*
* @author hubin
* @since 2016-01-23
*/
public class MybatisConfiguration extends Configuration {
/**
* 初始化调用
*/
public MybatisConfiguration() {
super();
this.mapUnderscoreToCamelCase = true;
languageRegistry.setDefaultDriverClass(MybatisXMLLanguageDriver.class);
}
db-column-underline为true来开启驼峰功能。
只要设置db-column-underline与map-underscore-to-camel-case任意一个参数为true,实体类的字段都会自动转下划线的格式。
map-underscore-to-camel-case > db-column-underline 为了歧义新版去掉 db-column-underline
动态数据源