ssm項目中在mybatis配置文件中添加如下配置,能夠將數據庫中user_name轉化成userName與實體類屬性對應,若是數據庫使用如user_name的命名方式,實體類採用駝峯命名。配置後無需寫resultMapper將數據庫字段和實體類屬性對應spring
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <settings> <setting name="mapUnderscoreToCamelCase" value="true" /> </settings> </configuration>
在spring boot項目中沒有mybatis.xml文件,配置文件application.properties中,加入配置項:數據庫
1 mybatis.configuration.mapUnderscoreToCamelCase=true 2 或 3 mybatis.configuration.map-underscore-to-camel-case=true
設爲true表示開啓駝峯轉換。通過試驗,兩種配置方法均可以。但若是同時配置,前者mybatis.configuration.mapUnderscoreToCamelCase的優先級更高mybatis