开发中常见用法
<insert id="insertSelective" parameterType="com.lwx.rental.core.db.po.RentalBindHistoryPo">
insert into t_rental_bind_history
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="guid != null">
guid,
</if>
<if test="companyGuid != null">
company_guid,
</if>
<if test="driverId != null">
driver_id,
</if>
<if test="operateType != null">
operate_type,
</if>
<if test="remark != null">
remark,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="updateTime != null">
update_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="guid != null">
#{guid,jdbcType=VARCHAR},
</if>
<if test="companyGuid != null">
#{companyGuid,jdbcType=VARCHAR},
</if>
<if test="driverId != null">
#{driverId,jdbcType=BIGINT},
</if>
<if test="operateType != null">
#{operateType,jdbcType=SMALLINT},
</if>
<if test="remark != null">
#{remark,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
可以看出,上述语句中,最后都有一个多余的逗号,如果不去除的话,sql语句执行时就会报错,而suffixOverrides正是用于去除这个逗号的,这样就不会有问题了
标签作用解释
-
prefix:给trim标签内的sql语句加上前缀
-
suffix:给trim标签内的sql语句加上后缀
-
suffixOverrides:去除多余的后缀,如:
suffixOverrides=","
,则表示去除trim标签内sql语句多余的逗号后缀 -
prefixOverrides:去除多余的前缀