mybatis 多條件多值批量更新

本文借鑑自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>

如果要修改的字段是多個的話,可以把判斷賦值的地方重複寫,然後改掉賦值字段的地方就好

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章