您的位置:首页 > 数据库 > MySQL

mysql 批量更新 update foreach

2015-12-24 17:06 676 查看
第一种方式

<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>


第二种方式

注意 需要在数据库添加 &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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: