mybatis駝峯式命名規則自動轉換:數據庫
示例:安全
<resultMap id ="UserInfoMap" type="com.example.mybaitsxml.dao.entity.User"> <result column="name_" property="name"/> <result column="sex" property="sex"/> <result column="age" property="age"/> <result column="class_no" property="classNo"/> </resultMap>
SpringBoot整合mybatis,開啓mybatis駝峯式命名規則自動轉換,一般根據配置文件不一樣分爲兩種方式。mybatis
#mybatis配置
mybatis:
typeAliasesPackage: com.example.mybaitsxml.dao.entity
mapperLocations: classpath:mapper/*.xml
configuration: map-underscore-to-camel-case: true
#mybatis配置
mybatis:
typeAliasesPackage: com.example.mybaitsxml.dao.entity
mapperLocations: classpath:mapper/*.xml
configLocation: classpath:/mybatis-config.xml
<?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>
注:關於xml文件,若是刪除或者註釋掉全部內容,會報錯:"Valid XML document must hava a root tag",若忽略這個報錯直接運行,程序報錯:app
「Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 11; columnNumber: 24; 文件提早結束。」spa
開啓mybatis駝峯式命名規則轉換能夠省去xml文件中resultMap編寫的麻煩,只須要爲resultType指定數據庫表對應的實體類便可,可是考慮程序的安全性以及映射靈活性,一般開發中仍是將resultMap結合使用。設計