Mybatis-Plus开启驼峰命名。
时间: 2024-01-11 08:45:59 浏览: 29
回答:可以在Mybatis-Plus的全局配置中设置开启驼峰命名。具体方式如下:
```
// 开启驼峰命名
GlobalConfig globalConfig = new GlobalConfig();
globalConfig.setDbConfig(new GlobalConfig.DbConfig().setColumnNaming(NamingStrategy.underline_to_camel));
```
这样设置后,Mybatis-Plus就会自动将下划线命名转换为驼峰命名了。
相关问题
mybatis-plus关闭驼峰xml
要关闭MyBatis-Plus的驼峰命名规则,可以在MyBatis的配置文件中添加如下设置:
```xml
<settings>
<setting name="mapUnderscoreToCamelCase" value="false"/>
</settings>
```
这样就可以关闭MyBatis-Plus默认的驼峰规则,将下划线命名方式转换为Java的驼峰命名方式。同时,在编写SQL语句的时候,也要遵循下划线命名方式,例如:
```xml
<select id="getUserById" parameterType="java.lang.Long" resultType="com.example.User">
SELECT id, user_name, password, create_time, update_time FROM user WHERE id=#{id}
</select>
```
这样,MyBatis-Plus就不会将下划线命名方式的表字段转换为驼峰命名方式的Java属性名。
配置mybatis-plus的驼峰转化
Mybatis-Plus 默认使用驼峰命名规则,如果需要启用下划线转驼峰规则,可以在配置文件中添加以下配置:
```xml
<configuration>
<global-config>
<db-config>
<!-- 开启驼峰命名 -->
<column-underline-to-camel>true</column-underline-to-camel>
<!-- 关闭大写命名 -->
<capital-mode>false</capital-mode>
</db-config>
</global-config>
</configuration>
```
其中,`column-underline-to-camel` 表示是否开启下划线转驼峰规则,`capital-mode` 表示是否开启大写命名。将 `column-underline-to-camel` 设置为 true 即可开启下划线转驼峰规则。