今天遇到个这么个问题:
原始代码:
<update id="updateCusSelect" parameterType="com.primecoss.model.XXXX">
update CUSTOMER_SELECT
<trim prefix="set" suffixOverrides=",">
<if test="sel1 != null and sel1 != ''">
SEL1 = #{sel1},
</if>
<if test="sel2 != null and sel2 != ''">
SEL2 = #{sel2},
</if>
</trim>
where CUSTOMER_ID = #{customerId}
</update>
在做mybatis更新数据时,因为我想到where条件中的唯一标识字段不需要更新所以就没写在trim里面,结果出现了如下错误:
这里的 sel1 和 sel2 两个字段都是空字符串 "" ,所以mybatis在拼接语句时报了上面的错误,并没有把这两个字段拼上,所有在写更新语句时最好(一定)要加上一个唯一标识的字段也就是表中设置主键的字段,以避免出现上面的错误
更新后的代码:
<update id="updateCusSelect" parameterType="com.primecoss.model.XXXX">
update CUSTOMER_SELECT
<trim prefix="set" suffixOverrides=",">
<if test="customerId != null and customerId != ''">
CUSTOMER_ID = #{customerId},
</if>
<if test="sel1 != null and sel1 != ''">
SEL1 = #{sel1},
</if>
<if test="sel2 != null and sel2 != ''">
SEL2 = #{sel2},
</if>
</trim>
where CUSTOMER_ID = #{customerId}
</update>
更改后错误解决。
若对你有所帮助,麻烦点个赞哈!!!
若对你有所帮助,麻烦点个赞哈!!!
若对你有所帮助,麻烦点个赞哈!!!
各位大佬若有批量插入时存在空值或空串的方法,受教。