文章目录
前言
MyBatis-Plus 提供了丰富的配置选项,以满足不同用户的需求。这些配置中,一部分继承自 MyBatis 原生支持的配置,另一部分则是 MyBatis-Plus 特有的扩展配置。
一、使用方式
1.Spring Boot 配置
mybatis-plus:
configuration:
# MyBatis 配置
map-underscore-to-camel-case: true
global-config:
# 全局配置
db-config:
# 数据库配置
id-type: auto
2.Spring MVC 配置
<bean id="sqlSessionFactory" class="com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mapperLocations" value="classpath*:mapper/**/*.xml"/>
<property name="typeAliasesPackage" value="com.your.domain"/>
<!-- 其他配置 -->
</bean>
二、常用配置
1.Base
1.1 configLocation
- 类型:
String
- 默认值:
null
配置示例:
mybatis-plus:
config-location: classpath:/mybatis-config.xml
1.2 mapperLocations
- 类型:
String[]
- 默认值:
["classpath*:/mapper/**/*.xml"]
配置示例:
mybatis-plus:
mapper-locations: classpath:/mapper/**.xml
1.3 typeAliasesPackage
- 类型:
String
- 默认值:
null
配置示例:
mybatis-plus:
type-aliases-package: com.your.domain
1.4 typeAliasesSuperType
- 类型:
Class<?>
- 默认值:
null
配置示例:
mybatis-plus:
type-aliases-super-type: com.your.domain.BaseEntity
1.5 typeHandlersPackage
- 类型:
String
- 默认值:
null
配置示例:
mybatis-plus:
type-handlers-package: com.your.typehandlers
2. Configuration
2.1 mapUnderscoreToCamelCase
- 类型:
boolean
- 默认值:
true
配置示例:
mybatis-plus:
configuration:
map-underscore-to-camel-case: true