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>

如果要修改的字段是多个的话,可以把判断赋值的地方重复写,然后改掉赋值字段的地方就好

 

 

 

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