mybatis在默认情况下,属性名和数据库字段名是一一对应的,例如:

若数据库字段名为:USER_ID

则java bean中属性字段对应因为:user_id(可不区分大小写)

 

但是java代码中实际上却不这样命名

java中一般采用驼峰命名:

数据库字段名:user_name

对应java实体bean:userName

而默认mybatis不会将二者自动映射,如果想要成功映射,则需要开启mybatis的驼峰命名规范自动映射

 

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

application.yml配置文件中:

 #开启驼峰命名规范自动映射
    configuration:
      map-underscore-to-camel-case: true

 

application.properties配置文件中:

 #开启驼峰命名规范自动映射
    mybatis.configuration.map-underscore-to-camel-case=true

 

posted on 2021-10-15 17:32  华安√  阅读(2210)  评论(0)    收藏  举报