mybatis 批量更新数据

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}
            <if test="item.operNum != null and item.operNum != ''">
                THEN num + #{item.operNum}
            </if>
            <if test="item.operNum == null or item.operNum == ''">
                THEN num
            </if>
    </foreach>
    END,
    update_time = CURRENT_TIMESTAMP
    WHERE id IN
    <foreach collection="entities" item="item" index="index" open="(" close=")" separator=",">
        #{item.id}
    </foreach>
</update>

 

posted @ 2024-02-03 00:40  武卡卡  阅读(28)  评论(0编辑  收藏  举报