下划线转驼峰命名的方法

下划线转驼峰命名

问题:

实体类中属性名采用驼峰命名

    private LocalDateTime createTime; //创建时间
    private LocalDateTime updateTime; //修改时间

数据库中表结构字段采用下划线命名

`create_time` datetime DEFAULT NULL COMMENT '创建时间',
`update_time` datetime DEFAULT NULL COMMENT '修改时间',

如果不使用映射的话,我们查询到的结果会显示为空,或者查询不到。

解决办法:

开启Mybatis的驼峰命名自动映射开关 create_time --------> createTime

(这里作者只提供了一种使用Mybatis解决的方法,下面三种修改方法采用自己的书写方法添加进去就行)

1.mybatis.xml

<configuration>
    <settings>
        <setting name="mapUnderscoreToCamelCase" value="true"/>
    </settings>
</configuration>

2.application.properties

Mybatis.configuration.map-underscore-to-camel-case=true

3.application.yml

#Mybatis配置
mybatis:
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
    #开启mybatis的驼峰命名自动映射
    map-underscore-to-camel-case: true

依赖

 <!--mybatis起步依赖-->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.2.2</version>    <!--这里版本号可以替换,根据自己的配置来-->
        </dependency>
posted @   韩续贤  阅读(194)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示