qq_37750143
大博主
2017-11-13 10:16

关于xml里面的拼接动态sql,批量插入的,不知道那种是对的

3
  • select
  • xml
  • sql
   <insert id="batchInsertGoods" >
        insert into dt.ec.goods
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="goodsId != null">
                goods_id,
            </if>
            <if test="platformNo != null">
                platform_no,
            </if>
            <if test="platformGoodsNo != null">
                platform_goods_no,
            </if>
            <if test="platformGoodsName != null">
                platform_goods_name,
            </if>
            <if test="styleNo != null">
                style_no,
            </if>
            <if test="styleName != null">
                style_name,
            </if>
            <if test="isStop != null">
                is_stop,
            </if>
            <if test="autoUpload != null">
                auto_upload,
            </if>
            <if test="uploadPercent != null">
                upload_percent,
            </if>
            <if test="shopPrice != null">
                shop_price,
            </if>
            <if test="safeNums != null">
                safe_nums,
            </if>
            <if test="onsellTime != null">
                onsell_time,
            </if>
            <if test="remark != null">
                remark,
            </if>
            create_time,
            update_time,
            <if test="status != null">
                status,
            </if>
            <if test="isDel != null">
                is_del,
            </if>
            <if test="hitsShelvesType != null">
                hits_shelves_type,
            </if>
            <if test="shopId != null">
                shop_id,
            </if>
            <if test="imageUrl != null">
                image_url,
            </if>
            <if test="tId != null">
                t_id,
            </if>
        </trim>
        values
        <foreach collection="simpleGoodsList" item="item" index="index">
            <trim prefix="values (" suffix=")" suffixOverrides=",">
                <if test="goodsId != null">
                    #{item.goodsId,jdbcType=INTEGER},
                </if>
                <if test="platformNo != null">
                    #{item.platformNo,jdbcType=VARCHAR},
                </if>
                <if test="platformGoodsNo != null">
                    #{item.platformGoodsNo,jdbcType=VARCHAR},
                </if>
                <if test="platformGoodsName != null">
                    #{item.platformGoodsName,jdbcType=VARCHAR},
                </if>
                <if test="styleNo != null">
                    #{item.styleNo,jdbcType=VARCHAR},
                </if>
                <if test="styleName != null">
                    #{item.styleName,jdbcType=VARCHAR},
                </if>
                <if test="isStop != null">
                    #{item.isStop,jdbcType=TINYINT},
                </if>
                <if test="autoUpload != null">
                    #{item.autoUpload,jdbcType=TINYINT},
                </if>
                <if test="uploadPercent != null">
                    #{item.uploadPercent,jdbcType=DECIMAL},
                </if>
                <if test="shopPrice != null">
                    #{item.shopPrice,jdbcType=DECIMAL},
                </if>
                <if test="safeNums != null">
                    #{item.safeNums,jdbcType=INTEGER},
                </if>
                <if test="onsellTime != null">
                    #{item.onsellTime,jdbcType=TIMESTAMP},
                </if>
                <if test="remark != null">
                    #{item.remark,jdbcType=VARCHAR},
                </if>
                now(),
                now(),
                <if test="status != null">
                    #{item.status,jdbcType=INTEGER},
                </if>
                <if test="isDel != null">
                    #{item.isDel,jdbcType=TINYINT},
                </if>
                <if test="hitsShelvesType != null">
                    #{item.hitsShelvesType,jdbcType=TINYINT},
                </if>
                <if test="shopId != null">
                    #{item.shopId,jdbcType=BIGINT},
                </if>
                <if test="imageUrl != null">
                    #{item.imageUrl,jdbcType=VARCHAR},
                </if>
                <if test="tId != null">
                    #{item.tId,jdbcType=VARCHAR},
                </if>
            </trim>
        </foreach>
    </insert>

<insert id="insertBatch" parameterType="List">
INSERT INTO TStudent(name,age)
<foreach collection="list" item="item" index="index" open="("close=")"separator="union all">
SELECT #{item.name} as a, #{item.age} as b FROM DUAL
</foreach>
</insert>

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

8条回答

为你推荐