mybatisplus驼峰
时间: 2023-08-19 11:15:30 浏览: 63
mybatis-plus驼峰命名是指在使用mybatis-plus框架时,将数据库表字段名和实体类属性名进行自动映射的规则。默认情况下,mybatis-plus会将实体类的属性名中的大写字母变成小写,并在大写字母前加上下划线,作为数据库表字段名。例如,数据库表字段为last_name,实体类属性名为lastName。[2]
要启用mybatis-plus的驼峰命名规则,需要在mybatis的配置文件mybatis-config.xml中进行配置。在该配置文件中,可以设置mapUnderscoreToCamelCase属性为true,表示开启驼峰命名规则的自动转换。[3]
另外,在application.yml文件中,也可以通过配置mybatis的typeAliasesPackage和mapperLocations属性来指定实体类的别名包和映射文件的位置。[1]
综上所述,mybatis-plus的驼峰命名规则可以通过配置mybatis的配置文件和application.yml文件来实现。
相关问题
mybatisplus驼峰失效
mybatisplus驼峰失效是因为mybatis-plus默认的驼峰命名规则是开启的,但在某些情况下会出现失效的情况。解决这个问题的方法有两种:
1. 使用对象包装工厂:
您可以在配置文件中指定使用MybatisMapWrapperFactory作为对象包装工厂。您可以在配置类中添加以下代码:
```java
@Bean
public ConfigurationCustomizer mybatisConfigurationCustomizer() {
return configuration ->
configuration.setObjectWrapperFactory(new MybatisMapWrapperFactory());
}
```
2. 配置全局驼峰命名策略:
您可以在配置文件中配置全局的驼峰命名策略。在Spring-Mybatis.xml中找到SqlSessionFactory配置,并添加以下属性:
```xml
<property name="globalConfig" ref="globalConfig" />
```
然后,在配置文件中配置GlobalConfig:
```xml
<bean id="globalConfig" class="com.baomidou.mybatisplus.core.config.GlobalConfig">
<property name="dbConfig" ref="dbConfig" />
<property name="sqlInjector" ref="sqlInjector" />
<property name="idType" value="AUTO" />
<property name="fieldStrategy" value="NOT_EMPTY" />
<property name="tablePrefix" value="" />
<property name="tablePrefix" value="" />
<property name="sqlParserCache" value="true" />
<property name="keyGenerator" ref="keyGenerator" />
<property name="metaObjectHandler" ref="metaObjectHandler" />
<property name="sqlSessionFactory" ref="sqlSessionFactory" />
</bean>
```
以上是解决mybatisplus驼峰失效的两种方法。您可以根据您的实际情况选择其中一种方法进行配置。
mybatisplus关闭驼峰
MybatisPlus是一个基于Mybatis的增强工具,它提供了许多实用的功能,其中包括将数据库下划线字段自动转换为Java驼峰命名规则的功能。如果你想关闭MybatisPlus的驼峰转换功能,可以按照以下两种方式进行配置:
1.在properties配置文件中添加如下配置:mybatis-plus.configuration.map-underscore-to-camel-case=false
2.在yml格式的配置文件中添加如下配置:mybatis-plus: configuration: map-underscore-to-camel-case: false