Springboot中MyBatis 自动转换 map-underscore-to-camel-case


在SpringBoot中使用MyBatis 都是通过配置完成的

mybatis默认是属性名和数据库字段名一一对应的,即 
数据库表列:user_name 
实体类属性:user_name

但是java中一般使用驼峰命名 
数据库表列:user_name 

 

 实体类属性:userName

 

 Mapper.xml中的userName

 

 在Springboot中,可以通过设置map-underscore-to-camel-case属性为true来开启驼峰功能。 
application.yml中:

mybatis:
  mapper-locations: classpath:mapping/*Mapper.xml
  type-aliases-package: com.herbert.demo.entity
  configuration:
    map-underscore-to-camel-case: true
    cache-enabled: false

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM