这种场景直接通过update语句更新即可,如:
1 |
UPDATE t_sys_user SET `desc` = 'CaseWhen-0' WHERE id IN (1001,1002,1003); |
1 2 3 4 5 6 7 8 9 10 11 |
<update id="updateForeach"> <foreach collection="list" item="param" separator=";"> UPDATE t_sys_user <set> <if test=" param.desc != null and param.desc != ''"> `desc` = #{param.desc} </if> </set> WHERE id = #{param.id} </foreach> </update> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<update id="updateBatchCaseWhen"> UPDATE t_sys_user <set> <trim prefix="`DESC`= CASE id" suffix="END,"> <foreach collection="list" item="param"> <if test="param.id != null"> WHEN #{param.id} THEN #{param.desc} </if> </foreach> </trim> <!-- <trim prefix="username = CASE id" suffix="END,"> <foreach collection="list" item="param"> <if test="param.username != null and param.username != ''"> WHEN #{param.} THEN #{param.username} </if> </foreach> </trim> --> </set> <where> id in <foreach collection="list" item="param" separator="," open="(" close=")"> #{param.id} </foreach> </where> </update> |