问题形容

MyBatis无奈查问出属性名和数据库字段名不完全相同的数据。

即:属性名和数据库字段名别离为驼峰命名下划线命名时查出的数据为NULL

问题剖析

MyBatis默认是属性名和数据库字段名一一对应的,即 

数据库表列:user_name 

实体类属性:user_name

然而java中个别应用驼峰命名 

数据库表列:user_name 

实体类属性:userName

解决方案

Spring Boot中,能够通过设置map-underscore-to-camel-case属性为true来开启驼峰性能。  

MyBatis配置: 

application.properties中:

1.  #开启驼峰命名转换2.  mybatis.configuration.map-underscore-to-camel-case=true 

application.yml中: 

1.  mybatis:2.    configuration:3.      map-underscore-to-camel-case: true

 应用该配置能够让MyBatis主动将SQL中查出来的带下划线命名的字段,主动转换为驼峰命名,再去匹配类中的属性。