1.由于是动态获取的字段名称,故在更新的时候需要动态的字段名
采用如下方式会报错:
update TB_PICTURES
set
#{TITLE}= ‘ ‘
2.加入判断的方式,即可动态设置字段名
每一个字段,都加入判断,符合判断则更新,即可动态设置字段名。
注意:每一个判断进去的语句后面必须加逗号,否则同样会报错。
1 update TB_PRODUCT 2 set 3 <if test="PRODUCT_IMG1 != null and PRODUCT_IMG1 != ‘‘"> 4 PRODUCT_IMG1 = ‘‘, 5 </if> 6 <if test="PARAMETER_IMG1 != null and PARAMETER_IMG1 != ‘‘"> 7 PARAMETER_IMG1 = ‘‘, 8 </if> 9 <if test="APPLICATION_IMG1 != null and APPLICATION_IMG1 != ‘‘"> 10 APPLICATION_IMG4 = ‘‘, 11 </if> 12 <if test="APPLICATION_IMG2 != null and APPLICATION_IMG2 != ‘‘"> 13 APPLICATION_IMG2 = ‘‘, 14 </if> 15 <if test="APPLICATION_IMG3 != null and APPLICATION_IMG3 != ‘‘"> 16 APPLICATION_IMG3 = ‘‘, 17 </if> 18 <if test="APPLICATION_IMG4 != null and APPLICATION_IMG4 != ‘‘"> 19 APPLICATION_IMG4 = ‘‘, 20 </if> 21 ID = ID 22 where 23 ID = #{ID}