配置属性如下:

属性

描述

id

SQL编号,用于标识这条SQL

parameterType

参数类型和select相同

flushCache

是否刷新缓存,插入时会刷新一级缓存和二级缓存,否则不刷新,默认为true

timeout

超时时间,单位为秒

statementType

STATEMENT、PREPARED(预编译)、CALLABLE(存储过程)中的一个

useGeneratedKeys

是否启JDBC的getGeneratedKeys方法来获取由数据库内部生成的主键,默认false

keyProperty

唯一标识属性,MyBatis会通过 getGeneratedKeys的返回值来设置。复合主键用,隔开。

keyColumn

通过生成的键值设置表中的列名这个设置只会在某些数据库中(PostgreSQL)是必须的,不能和keyProperty复用

databaseId

超时时间,单位为秒

statementType

数据库厂商标识

主键回填:

useGeneratedKeys="true" keyProperty="id"

自定义主键:

<insert id="insertSelective" parameterType="com.bob.analyst.model.User">
<selectKey keyProperty="id" resultType="long" order="BEFORE">
.....
</selectKey>
.....
</insert>

update 和 delete

它们比较普通,这边不做介绍

sql元素:

sql元素的作用在于定义一条SQL的一部分,方便后面的SQL引用它。

<sql id="Base_Column_List">
id, user_name, mobile, password, age, is_delete, nickname, email, type, create_time,
update_time
</sql>
<sql id="users">
${users}.id, ${users}.user_name, ${users}.mobile, ${users}.password
update_time
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="users">
<property name="user" value="u"/>
</include>
from tbl_user
where id = #{id,jdbcType=BIGINT}
</select>

支持变量传递