1. 程式人生 > 其它 >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