本文借鉴自Mybatis中进行批量更新(updateBatch)
近来常用,留个记忆
<update id="batchUpdate" parameterType="java.util.List">
update demo_table
<trim prefix="set" suffixOverrides=",">
field1 =
<foreach collection="list" item="item" open="case " close=" end,">
when field2 = #{item.value2} AND field3 = #{item.value3} then #{item.value1}
</foreach>
field4 =
<foreach collection="list" item="item" open="case " close=" end,">
when field2 = #{item.value2} AND field3 = #{item.value3} then
<choose>
<when test="item.value4 != null">
#{item.value4}
</when>
<otherwise>field4</otherwise>
</choose>
</foreach>
</trim>
<where>
<foreach collection="list" item="item" open="( " separator=") or (" close=" )">
field2 = #{item.value2} AND field3 = #{item.value3}
</foreach>
</where>
</update>
如果要修改的字段是多个的话,可以把判断赋值的地方重复写,然后改掉赋值字段的地方就好
————————————————
版权声明:本文为优快云博主「aklin47」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.youkuaiyun.com/aklin47/article/details/81026930