MyBatis bulk insert and delete

1. Bulk Insert:

<insert id="insertRecord">
        INSERT INTO tb_record(
        detail,
        status
        ) VALUES
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.detail},
            #{item.status}
            )
        </foreach>
</insert>
复制代码

2. Batch update:

<update `id`="updateInfo">
        UPDATE tb_info
        <trim prefix="set" suffixOverrides=",">
            <trim prefix="detail =case" suffix="end,">
                <foreach collection="list" item="item" index="index">
                    <if test="item.detail!=null">
                        when id=#{item.id} then #{item.detail}
                    </if>
                </foreach>
            </trim>
            <trim prefix="city =case" suffix="end,">
                <foreach collection="list" item="item" index="index">
                    <if test="item.city!=null">
                        when id=#{item.id} then #{item.city}
                    </if>
                </foreach>
            </trim>
        </trim>
        WHERE
        <foreach collection="list" separator="or" item="item" index="index" >
            id=#{item.id}
        </foreach>
</update>
复制代码

Reproduced in: https: //juejin.im/post/5cff0debf265da1bc5525975

Guess you like

Origin blog.csdn.net/weixin_33816821/article/details/91427690