这种场景直接通过update语句更新即可,如:
UPDATE t_sys_user SET `desc` = "CaseWhen-0" WHERE id IN (1001,1002,1003);
&allowMultiQueries=true
这个才可以执行<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>
<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>
到此这篇关于MySQL实现数据批量更新功能详解的文章就介绍到这了,更多相关MySQL数据批量更新内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!