Mybatis的批量删除语句

本文介绍了一种使用MyBatis进行批量更新的方法,通过foreach元素遍历集合中的每一条记录,根据需要更新的字段生成对应的SQL语句。同时,为了支持多条SQL语句的批量提交,对数据库连接URL进行了配置,启用了多查询功能。

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


    <update id="modAllItems" parameterType="com.arvin.po.ItemsCustom">
        <foreach collection="list" item="items" separator=";">
            UPDATE items
            <set>
                <if test="items.name != null">
                      name = #{items.name},
                </if>
                <if test="items.price != null">
                     price = #{items.price},
                </if>
                <if test="items.detail != null">
                    detail  = #{items.detail},
                </if>
                <if test="items.createtime!= null">
                    createtime = #{items.createtime},
                </if>

            </set>
            WHERE id = #{items.id}
        </foreach>
    </update>

2.要批量提交多条执行语句,所以在db,properties 文件中

jdbc.url = jdbc:mysql://localhost:3306/mybatis?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值