记录一次开发中的mybatis的批量更新需求

本文展示了一个使用MyBatis进行批量更新操作的代码实例,通过动态SQL实现对多个活动交换记录的字段更新,包括截止日期、更新者和更新时间。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

直接贴代码

<update id="updateActivityExchangeByIds" parameterType="TDeptActivityExchange">
        update t_dept_activity_exchange
        <trim prefix="set" suffixOverrides=",">
            <trim prefix="EXCHANGE_DEADLINE =case" suffix="end,">
                <foreach collection="activityExchanges" item="item" index="index">
                    <if test="item.exchangeDeadline!=null">
                        when ID=#{item.id} then #{item.exchangeDeadline}
                    </if>
                </foreach>
            </trim>
            <trim prefix=" UPDATE_BY =case" suffix="end,">
                <foreach collection="activityExchanges" item="item" index="index">
                    <if test="item.updateBy!=null">
                        when ID=#{item.id} then #{item.updateBy}
                    </if>
                </foreach>
            </trim>

            <trim prefix="UPDATE_TIME =case" suffix="end," >
                <foreach collection="activityExchanges" item="item" index="index">
                    <if test="item.updateTime!=null">
                        when ID=#{item.id} then #{item.updateTime}
                    </if>
                </foreach>
            </trim>
        </trim>
        where DELETE_FLG = 0 AND
        <foreach collection="activityExchanges" separator="or" item="item" index="index" >
            ID=#{item.id}
        </foreach>
    </update>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值