更新多条记录为多个字段为不同的值
比较普通的写法,是通过循环,依次执行update语句。
Mybatis写法如下:
1 2 3 4 5 6 7 8 9
|
<update id="updateBatch" parameterType="java.util.List"> <foreach collection="list" item="item" index="index" open="" close="" separator=";"> update course <set> name=${item.name} </set> where id = ${item.id} </foreach> </update>
|
<!-- 批量移除固件白名单 -->
<select id="batchRemove" resultType="java.lang.Integer">
update cm_device_firmware_white set del_flag = '1',del_time=now() where
<foreach collection="firmwareWhiteList" item="item" open="(" close=")" separator="OR">
del_flag = '0' and user_id = #{item.userId} and firmware_id = #{item.firmwareId}
</foreach>
</select>