mybatis 批量插入 和批量更新

mybatis 批量插入 和批量更新

一、批量插入

<insert id="insert" parameterType="list">
        insert into aaa(
        id,
        name,
        create_time,
        update_time,
        create_user,
        update_user)
        VALUES
        <foreach collection ="list" item="bbb" separator =",">
            (
            #{bbb.id},
            #{bbb.name},
            #{bbb.create_time},
            #{bbb.update_time},
            #{bbb.create_user},
            #{bbb.update_user}
            )
        </foreach >
    </insert>

二、批量更新

<update id="methodName" parameterType="list">
        update ccc
        <trim prefix="set" suffixOverrides=",">
            <trim prefix="student_status =case" suffix="end,">
                    <foreach collection="list" item="item" index="index">
                        <!--studentStatus 字段 更新 -->
                        <if test="item.studentStatus !=null and item.studentStatus != ''">
                            when id=#{item.id} then #{item.studentStatus}
                        </if>
                    </foreach>
                </trim>
            <trim prefix="name =case" suffix="end,">
                <foreach collection="list" item="item" index="index">
                    <!--name 字段跟新 -->
                    <if test="item.name !=null and item.name != ''">
                        when id=#{item.id} then #{item.name}
                    </if>
                </foreach>
            </trim>
        </trim>
        where id in
                    <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
                        #{item.id,jdbcType=BIGINT}
                    </foreach>
    </update>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值