本文借鑑自Mybatis中進行批量更新(updateBatch)
近來常用,留個記憶
<update id="batchUpdate" parameterType="java.util.List">
update demo_table
set field1 =
<foreach collection="list" item="item" open="case " close=" end">
when field2 = #{item.value2} AND field3 = #{item.value3} then #{item.value1}
</foreach>
<where>
<foreach collection="list" item="item" open="( " separator=") or (" close=" )">
field2 = #{item.value2} AND field3 = #{item.value3}
</foreach>
</where>
</update>
如果要修改的字段是多個的話,可以把判斷賦值的地方重複寫,然後改掉賦值字段的地方就好