Bootstrap

springboot + mybatis批量更新

语法示例

<update id="updateBatch" parameterType="java.util.List">  
    UPDATE your_table  
    SET column1 = (CASE id  
        <foreach collection="list" item="item" index="index" separator=" ">  
            WHEN #{item.id} THEN #{item.column1}  
        </foreach>  
    END),  
    column2 = (CASE id  
        <foreach collection="list" item="item" index="index" separator=" ">  
            WHEN #{item.id} THEN #{item.column2}  
        </foreach>  
    END)  
    WHERE id IN  
    <foreach collection="list" item="item" open="(" separator="," close=")">  
        #{item.id}  
    </foreach>  
</update>

DEMO

UPDATE TABLE_NAME 
SET column1 = ( CASE id WHEN 1 THEN 'value1' 
						WHEN 2 THEN 'value2' 
END ),
   column1 = ( CASE id WHEN 1 THEN 'value1' 
					   WHEN 2 THEN 'value2' 
END ) 
WHERE id IN (1,2)
;