trim 用于去掉字符
prefix 前缀
prefixOverrides 去掉第一个标识符(跟在前缀后面第一个)
<sql id="searchByPro">
<trim prefix="WHERE" prefixOverrides="AND|OR">
<if test="id != null AND id != ''">
AND id = #{id}
</if>
<if test="taskId != null AND taskId != ''">
AND task_id = #{taskId}
</if>
<if test="taskIdentifier != null AND taskIdentifier != ''">
AND task_identifier = #{taskIdentifier}
</if>
<if test="processTime != null AND processTime != ''">
AND process_time = #{processTime}
</if>
<if test="time != null AND time != ''">
AND time = #{time}
</if>
</trim>
</sql>
如果属性都不为空相当于
select *from A where id='' and task_id='' and task_identifier = '' and process_time = '' and time = ''
prefix 前缀
suffixOverrides 去掉最后一个符号
<sql id="updateByPo">
<trim prefix="SET" suffixOverrides=",">
<if test="id != null">
id = #{id},
</if>
<if test="taskId != null">
task_id = #{taskId},
</if>
<if test="taskIdentifier != null">
task_identifier = #{taskIdentifier},
</if>
<if test="processTime != null">
process_time = #{processTime},
</if>
<if test="id != null">
id = #{id},
</if>
<if test="time != null">
time = #{time},
</if>
</trim>
</sql>
如果属性不为空相当于
update A set id = '',task_id='',....,time=''
selectKey 用于解决insert是插入主键的值(参数不提供主键)
<selectKey keyProperty="目标属性" resultType="结果类型" order="BEFORE/AFTER">
//
</selectKey>
需要注意order属性,像MySQL一类支持自动增长类型的数据库中,order需要设置为after才会取到正确的值,而Oracle一类取序列的情况,需要设置为before,否则会报错。