目录
- 一、mybatis驼峰式命名
- 二、mybatisPlus默认开启驼峰命名映射
一、mybatis驼峰式命名
方法一:
- 使用前提:数据库表设计按照规范“字段名中各单词使用下划线"_"划分”;
- 使用好处:省去mapper.xml文件中繁琐编写表字段列表与表实体类属性的映射关系,即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> <!-- 开启驼峰,开启后,只要数据库字段和对象属性名字母相同,无论中间加多少下划线都可以识别 --> <setting name="mapUnderscoreToCamelCase" value="true" /> </settings> </configuration>
方法三:
application.yml文件指定配置文件
mybatis: typeAliasesPackage: com.example.mybaitsxml.dao.entity mapperLocations: classpath:mapper/*.xml configLocation: classpath:/mybatis-config.xml
二、mybatisPlus默认开启驼峰命名映射
也可以关闭
mybatis-plus: configuration: #在映射实体或者属性时,将数据库中表名和字段名中的下划线去掉,按照驼峰命名法映射 address_book ---> addressBook map-underscore-to-camel-case: false
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)