mybatis 批量更新数据

余寿

关注

阅读 13

2024-02-04

int updateBatch(@Param("entities") List<Drug> entities);

<update id="updateBatch" parameterType="java.util.List">
    UPDATE drug
    SET num = CASE
    <foreach collection="entities" item="item" index="index" open="" close="" separator=" ">
        WHEN id = #{item.id} THEN num + #{item.operNum}
    </foreach>
    END,
    update_time = CURRENT_TIMESTAMP
    WHERE id IN
    <foreach collection="entities" item="item" index="index" open="(" close=")" separator=",">
        #{item.id}
    </foreach>
</update>

 



精彩评论(0)

0 0 举报