在 Spring Boot 项目中,Mybatis-Plus 默认开启了自动驼峰设置,将数据库中的下划线命名自动转换为 Java 驼峰命名。如果需要关闭自动驼峰设置,需要在 Spring.xml 中配置 com.baomidou.mybatisplus.entity.GlobalConfiguration

首先,定义一个 bean 初始化 GlobalConfiguration,例如:

<bean id="globalConfig" class="com.baomidou.mybatisplus.entity.GlobalConfiguration">
    <property name="dbColumnUnderline" value="true"/>
</bean>

这里设置 dbColumnUnderline 为 true,表示关闭下划线转驼峰功能。然后在定义 Mybatis-Plus 的 SqlSessionFactory 时,将该 bean 注入进去:

<bean id="sqlSessionFactory" class="com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="globalConfig" ref="globalConfig"/>
</bean>

这样就可以去掉自动驼峰设置,并且可以自定义 GlobalConfiguration 的其他属性。

Spring Boot Mybatis-Plus 去除自动驼峰设置:在 Spring.xml 中配置 GlobalConfiguration

原文地址: https://www.cveoy.top/t/topic/otyK 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录