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结合使用。设计