Mybatis 动态添加多条数据SQL

 1. 配置文件中一定要添加 allowMultiQueries=true 的作用

       1.可以在sql语句后携带分号,实现多语句执行
       2.可以执行批处理,同时发出多个SQL语句。

2. 动态SQL语句列子: 

 <insert id="insertSellVipPersonList" parameterType="java.util.List">
        <foreach collection="list" item="item">
        INSERT INTO sell_vip_person
        (
            <trim suffixOverrides=",">
                <if test="item.shopId!=null">
                    shop_id,
                </if>
                <if test="item.paymentId!=null">
                    payment_id,
                </if>
                <if test="item.billType!=null">
                    bill_type,
                </if>
                <if test="item.sell1!=null">
                    sell1,
                </if>
                <if test="item.sellJobNum!=null">
                    sell_job_num,
                </if>
                <if test="item.sellName!=null">
                    sell_name,
                </if>
                <if test="item.sell1Dept!=null">
                    sell1_dept,
                </if>
                <if test="item.sell1KpiRatio!=null">
                    sell1_kpi_ratio,
                </if>
                <if test="item.createAt!=null">
                    create_at,
                </if>
                <if test="item.updateAt!=null">
                    update_at
                </if>
            </trim>
        )
        VALUES
            (
                <trim suffixOverrides=",">
                    <if test="item.shopId!=null">
                        #{item.shopId},
                    </if>
                    <if test="item.paymentId!=null">
                        #{item.paymentId},
                    </if>
                    <if test="item.billType!=null">
                        #{item.billType},
                    </if>
                    <if test="item.sell1!=null">
                        #{item.sell1},
                    </if>
                    <if test="item.sellJobNum!=null">
                        #{item.sellJobNum},
                    </if>
                    <if test="item.sellName!=null">
                        #{item.sellName},
                    </if>
                    <if test="item.sell1Dept!=null">
                        #{item.sell1Dept},
                    </if>
                    <if test="item.sell1KpiRatio!=null">
                        #{item.sell1KpiRatio},
                    </if>
                    <if test="item.createAt!=null">
                        #{item.createAt},
                    </if>
                    <if test="item.updateAt!=null">
                        #{item.updateAt}
                    </if>
                </trim>
            );
        </foreach>
    </insert>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值