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