springboot mybatis配置下划线转驼峰

mybatis配置下划线转驼峰 特别需要注意的是,只可以下划线转驼峰,不可以驼峰转下划线,即只能是从数据库中查出来的结果对应字段(下划线)转成实体类的对应属性(驼峰) 比如下面的语句,where user_name这个字段需要和数据库表里面的字段保持一致

<select id="getUserList" resultType="com.joshua317.demo3.entity.User">
        select * from user where user_name = #{userName};
    </select>

对于数据库中的字段下划线字段转驼峰,可以通过resultmap来做的,但是resultmap太过繁琐,所以不再赘述,我们可以通过简单配置非方式实现

#配置文件 application.yml
mybatis:
  configuration:
    #下划线转驼峰
    map-underscore-to-camel-case: true

#如果配置文件是application.properties
#旧版本
mybatis.configuration.mapUnderscoreToCamelCase=true 
#新版本
mybatis.configuration.map-underscore-to-camel-case=true

 

posted @ 2024-03-08 15:03  joshua317  阅读(344)  评论(0编辑  收藏  举报