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 @   武卡卡  阅读(52)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
历史上的今天:
2020-02-03 Vue - 动态绑定class

喜欢请打赏

扫描二维码打赏

支付宝打赏

点击右上角即可分享
微信分享提示