SpringBoot中MyBatis属性映射之开启驼峰命名
今天使用
SpringBoot整合MyBatis开发时,发现从数据库中查询到的结果封装到javabean中,只要表中有下划线的字段,就会出现null值
MyBatis默认是属性名和数据库字段名一一对应的,即
数据库表列:user_name
实体类属性:user_name
但是java中一般使用驼峰命名
数据库表列:user_name
实体类属性:userName
在SpringBoot中,可以通过设置map-underscore-to-camel-case属性为true来开启驼峰功能:
mybatis:
configuration:
map-underscore-to-camel-case: true # 开启驼峰命名

浙公网安备 33010602011771号