mybatis中mapUnderscoreToCamelCase自動駝峰命名轉換
阿新 • • 發佈:2018-11-29
ssm專案中在mybatis配置檔案中新增以下配置,可以將資料庫中user_name轉化成userName與實體類屬性對應,如果資料庫使用如user_name的命名方式,實體類採用駝峰命名。配置後無需寫resultMapper將資料庫欄位和實體類屬性對應
<?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的優先順序更高