数据库
首页 > 数据库> > mysql 批量更新 update foreach

mysql 批量更新 update foreach

作者:互联网

第一种方式:一条update
<update id="updateThreadreturnList" parameterType="java.util.List">
update tb_thread set isDelete=0
where threadId in (
<foreach collection="list" item="item" index="index" open="" close="" separator=",">
#{item.threadId}
</foreach>
)
</update>
第二种方式:多条update
注意 需要在数据库添加 &allowMultiQueries=true
jdbc:mysql://192.168.1.109:3306/healthmanage?characterEncoding=utf-8&allowMultiQueries=true
<update id="updateQuestionseleteTempalteList" parameterType="java.util.List">
<foreach collection="list" item="item" index="index">
update tb_question_template_seleteitem_detail set selectedName=#{item.selectedName}
where 1=1 and selectedId =#{item.selectedId };

</foreach>
</update>
————————————————
版权声明:本文为CSDN博主「Jesse-Xue」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_38809962/article/details/79610348

标签:set,allowMultiQueries,threadId,update,item,foreach,mysql
来源: https://www.cnblogs.com/javalinux/p/15534019.html