@TableName

  • 描述:表名注解,项目默认会进行驼峰转换,使用该注解后,表名就不会进行驼峰转换(比如不会将RoleUserRef转换为role_user_ref)
属性类型必须指定默认值描述
value String ""

字符串类型,不是必填,用来指定数据表名称,如RoleUserRef

@TableName(value = "RoleUserRef")
public class RoleUserRef implements Serializable {
.....
}
schema String ""

指定模式名称。如果使用的是 mysql 数据库,则指定数据库名称。如果使用的是 oracle,则为 schema,例如:schema="scott",其中:scott 就是 oracle 中的 schema。下面以mysql为例,TS_Conf_Test是mysql的数据库名称:

@TableName(value = "RoleUserRef", schema = "TS_Conf_Test")
public class RoleUserRef implements Serializable {
.....
}
keepGlobalPrefix boolean false 是否保持使用全局的 tablePrefix 的值(如果设置了全局 tablePrefix 且自行设置了 value 的值)(@since 3.1.1)
resultMap String ""

对应 Mapper XML 文件中 <resultMap> 标签的 id 属性的值

@TableName(value = "RoleUserRef", resultMap = "resultMap")
public class RoleUserRef implements Serializable {
.....
}

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.travelsky.csgl.dao.conf.RoleUserRefMapper">
<resultMap id="resultMap" type="com.travelsky.csgl.model.DO.Conf.RoleUserRef">
<id column="rur_sid" property="rurSid"/>
<result column="rur_project_sid" property="rurProjectSid"/>
autoResultMap boolean false 控制是否自动构建 resultMap 并使用它,如果你手动设置 resultMap 则不会进行自动构建并注入 resultMap(@since 3.1.2)

关于 `autoResultMap` 的说明

MyBatis Plus 会自动构建一个 ResultMap 并注入到 mybatis 里(一般用不上)。下面讲两句:因为 MyBatis Plus 底层是 mybatis,所以一些 mybatis 的常识你要知道,MyBatis Plus 只是帮你注入了常用 crud 到 mybatis 里。注入之前可以说是动态的(根据你 entity 的字段以及注解变化而变化),但是注入之后是静态的(等于你写在 xml 的东西)而对于直接指定typeHandler,mybatis 只支持你写在2个地方:

  • 定义在 resultMap 里,只作用于 select 查询的返回结果封装

  • 定义在 insert 和 update sql 的 #{property} 里的 property 后面(例:#{property,typehandler=xxx.xxx.xxx}),只作用于设置值而除了这两种直接指定 typeHandler,mybatis 有一个全局的扫描你自己的 typeHandler 包的配置,这是根据你的 property的类型去找 typeHandler 并使用。

posted @ 2021-05-26 10:42  coco9821  阅读(641)  评论(0编辑  收藏  举报