目錄
一、mybatis駝峰式命名
二、mybatisPlus默認(rèn)開(kāi)啟駝峰命名映射
一、mybatis駝峰式命名
方法一:
使用前提:數(shù)據(jù)庫(kù)表設(shè)計(jì)按照規(guī)范“字段名中各單詞使用下劃線"_"劃分”;
使用好處:省去mapper.xml文件中繁瑣編寫(xiě)表字段列表與表實(shí)體類屬性的映射關(guān)系,即resultMap。
示例:
<resultMap type="io.renren.modules.generator.entity.TokenEntity" id="tokenMap">
<result property="id" column="id"/>
<result property="userId" column="user_id"/>
<result property="token" column="token"/>
<result property="expireDate" column="expire_date"/>
<result property="updateDate" column="update_date"/>
</resultMap>
方法二:
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>
<!-- 開(kāi)啟駝峰,開(kāi)啟后,只要數(shù)據(jù)庫(kù)字段和對(duì)象屬性名字母相同,無(wú)論中間加多少下劃線都可以識(shí)別 -->
<setting name="mapUnderscoreToCamelCase" value="true" />
</settings>
</configuration>
方法三:
application.yml文件指定配置文件文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-632748.html
mybatis:
typeAliasesPackage: com.example.mybaitsxml.dao.entity
mapperLocations: classpath:mapper/*.xml
configLocation: classpath:/mybatis-config.xml
二、mybatisPlus默認(rèn)開(kāi)啟駝峰命名映射
也可以關(guān)閉文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-632748.html
mybatis-plus:
configuration:
#在映射實(shí)體或者屬性時(shí),將數(shù)據(jù)庫(kù)中表名和字段名中的下劃線去掉,按照駝峰命名法映射 address_book ---> addressBook
map-underscore-to-camel-case: false
到了這里,關(guān)于Mybatis/Mybatis-Plus駝峰式命名映射的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!