一、 同时更新多条数据的同一个字段的同一个值
<update id="updatePicturePostId">
update bbs_pictures set post_id = #{postId}
where user_id = #{userId} and picture_name in
(<foreach collection="pictureName" item="item" separator="," >
#{item}
</foreach>)
</update>
二、 同时更新多条数据的同一个字段的不同值
<update id="updatePicturePostId">
<foreach collection="pictureName" item="item" separator="," >
update bbs_pictures set post_id = #{item.id}
where user_id = #{userId} and picture_name in #{item.name}
</foreach>)
</update>
本文介绍了使用MyBatis进行批量数据更新的方法,包括如何同时更新多条记录的相同字段到同一值,以及如何更新多条记录的相同字段到不同值。通过具体的XML配置示例展示了两种批量更新操作的技术细节。
1650





