大博主 2017-11-13 10:16 采纳率: 38.9%
浏览 1867
已结题

关于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条回答 默认 最新

  • 关注

    自己先跑数据库查询 看生成的语句 这没办法看

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog