码迷,mamicode.com
首页 > 其他好文 > 详细

mybatis父子表批量插入

时间:2016-12-07 13:29:23      阅读:893      评论:0      收藏:0      [点我收藏+]

标签:rest   dex   yam   account   cti   restart   parameter   over   --   

 <!--父子表批量插入  -->
<insert id="insertBatch" parameterType="com.niwopay.dto.benifit.JFOrderVipDTO">
begin
           insert into TB_JF_ORDER
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="orderId != null" >
        ORDER_ID,
      </if>
      <if test="extOrderId != null" >
        EXT_ORDER_ID,
      </if>
      <if test="deviceChannel != null" >
        DEVICE_CHANNEL,
      </if>
      <if test="bizChannel != null" >
        BIZ_CHANNEL,
      </if>
      <if test="orderType != null" >
        ORDER_TYPE,
      </if>
      <if test="userId != null" >
        USER_ID,
      </if>
      <if test="orderDate != null" >
        ORDER_DATE,
      </if>
      <if test="orderAmount != null" >
        ORDER_AMOUNT,
      </if>
      <if test="productAmount != null" >
        PRODUCT_AMOUNT,
      </if>
      <if test="payAmount != null" >
        PAY_AMOUNT,
      </if>
      <if test="fee != null" >
        FEE,
      </if>
      <if test="sales != null" >
        SALES,
      </if>
      <if test="freight != null" >
        FREIGHT,
      </if>
      <if test="deliveryState != null" >
        DELIVERY_STATE,
      </if>
      <if test="orderState != null" >
        ORDER_STATE,
      </if>
      <if test="orderDesc != null" >
        ORDER_DESC,
      </if>
      <if test="remark != null" >
        REMARK,
      </if>
      <if test="createDate != null" >
        CREATE_DATE,
      </if>
      <if test="payDate != null" >
        PAY_DATE,
      </if>
      <if test="finishDate != null" >
        FINISH_DATE,
      </if>
      <if test="returnDate != null" >
        RETURN_DATE,
      </if>
      <if test="closeDate != null" >
        CLOSE_DATE,
      </if>
      <if test="deliveryDate != null" >
        DELIVERY_DATE,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="orderId != null" >
        #{orderId,jdbcType=VARCHAR},
      </if>
      <if test="extOrderId != null" >
        #{extOrderId,jdbcType=VARCHAR},
      </if>
      <if test="deviceChannel != null" >
        #{deviceChannel,jdbcType=VARCHAR},
      </if>
      <if test="bizChannel != null" >
        #{bizChannel,jdbcType=VARCHAR},
      </if>
      <if test="orderType != null" >
        #{orderType,jdbcType=CHAR},
      </if>
      <if test="userId != null" >
        #{userId,jdbcType=VARCHAR},
      </if>
      <if test="orderDate != null" >
        #{orderDate,jdbcType=CHAR},
      </if>
      <if test="orderAmount != null" >
        #{orderAmount,jdbcType=VARCHAR},
      </if>
      <if test="productAmount != null" >
        #{productAmount,jdbcType=VARCHAR},
      </if>
      <if test="payAmount != null" >
        #{payAmount,jdbcType=VARCHAR},
      </if>
      <if test="fee != null" >
        #{fee,jdbcType=VARCHAR},
      </if>
      <if test="sales != null" >
        #{sales,jdbcType=VARCHAR},
      </if>
      <if test="freight != null" >
        #{freight,jdbcType=VARCHAR},
      </if>
      <if test="deliveryState != null" >
        #{deliveryState,jdbcType=CHAR},
      </if>
      <if test="orderState != null" >
        #{orderState,jdbcType=CHAR},
      </if>
      <if test="orderDesc != null" >
        #{orderDesc,jdbcType=VARCHAR},
      </if>
      <if test="remark != null" >
        #{remark,jdbcType=VARCHAR},
      </if>
      <if test="createDate != null" >
        #{createDate,jdbcType=DATE},
      </if>
      <if test="payDate != null" >
        #{payDate,jdbcType=DATE},
      </if>
      <if test="finishDate != null" >
        #{finishDate,jdbcType=DATE},
      </if>
      <if test="returnDate != null" >
        #{returnDate,jdbcType=DATE},
      </if>
      <if test="closeDate != null" >
        #{closeDate,jdbcType=DATE},
      </if>
      <if test="deliveryDate != null" >
        #{deliveryDate,jdbcType=DATE},
      </if>
    </trim>;
    
    insert into TB_JF_ORDER_VIP
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="orderId != null" >
        ORDER_ID,
      </if>
      <if test="accountName != null" >
        ACCOUNT_NAME,
      </if>
      <if test="cardNo != null" >
        CARD_NO,
      </if>
      <if test="bankName != null" >
        BANK_NAME,
      </if>
      <if test="province != null" >
        PROVINCE,
      </if>
      <if test="city != null" >
        CITY,
      </if>
      <if test="branch != null" >
        BRANCH,
      </if>
      <if test="cpTradingStatus != null" >
        CP_TRADING_STATUS,
      </if>
      <if test="bankCardId != null" >
        BANK_CARD_ID,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="orderId != null" >
        #{orderId,jdbcType=VARCHAR},
      </if>
      <if test="accountName != null" >
        #{accountName,jdbcType=VARCHAR},
      </if>
      <if test="cardNo != null" >
        #{cardNo,jdbcType=VARCHAR},
      </if>
      <if test="bankName != null" >
        #{bankName,jdbcType=VARCHAR},
      </if>
      <if test="province != null" >
        #{province,jdbcType=VARCHAR},
      </if>
      <if test="city != null" >
        #{city,jdbcType=VARCHAR},
      </if>
      <if test="branch != null" >
        #{branch,jdbcType=VARCHAR},
      </if>
      <if test="cpTradingStatus != null" >
        #{cpTradingStatus,jdbcType=CHAR},
      </if>
      <if test="bankCardId != null" >
        #{bankCardId,jdbcType=CHAR},
      </if>
    </trim>;
    end;
</insert>

1、然后调用public int batchUpdate(final String statementName, final List<?> parameters);传入paramter参数的集合即可。

这种方式使用批量插入父子表。

2、不需要批量插入,但是插入一张主表的同时插入多张字表

  <insert id="insertQuotePlan" parameterType="com.taolue.api.interf.insurance.dto.QuotePlanDTO">
    begin
    insert into TB_CAR_INSURANCE_QUOTA_PLAN
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="QuotePlanID != null" >
        QUOTA_PLAN_ID,
      </if>
      <if test="userId != null" >
        USER_ID,
      </if>
      <if test="CityID != null" >
        CITY_ID,
      </if>
      <if test="VipCarID != null" >
        VIP_CAR_ID,
      </if>
      <if test="InsureStartDate != null" >
        INSURE_START_DATE,
      </if>
      <if test="BusinessStartDate != null" >
        BUSINESS_START_DATE,
      </if>
      <if test="createTime != null" >
        CREATE_TIME,
      </if>
      <if test="itemKind != null" >
        INTEM_KIND,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="QuotePlanID != null" >
        #{QuotePlanID,jdbcType=VARCHAR},
      </if>
      <if test="userId != null" >
        #{userId,jdbcType=VARCHAR},
      </if>
      <if test="CityID != null" >
        #{CityID,jdbcType=VARCHAR},
      </if>
      <if test="VipCarID != null" >
        #{VipCarID,jdbcType=VARCHAR},
      </if>
      <if test="InsureStartDate != null" >
        #{InsureStartDate,jdbcType=VARCHAR},
      </if>
      <if test="BusinessStartDate != null" >
        #{BusinessStartDate,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null" >
        #{createTime,jdbcType=DATE},
      </if>
      <if test="itemKind != null" >
        #{itemKind,jdbcType=CLOB},
      </if>
    </trim>;
    <if test="quotePriceList != null and quotePriceList.size>0" >
    <foreach collection="quotePriceList" item="item" index="index">
       insert into TB_CAR_INSURANCE_QUOTA_PRICE (quota_id,quota_plan_id,company_id,company_name,company_code) values (#{item.quotaId},#{QuotePlanID},#{item.companyId},#{item.companyName},#{item.companyCode});
    </foreach>
     </if>
    end;
   </insert> 

 

mybatis父子表批量插入

标签:rest   dex   yam   account   cti   restart   parameter   over   --   

原文地址:http://www.cnblogs.com/lijiale/p/6140486.html

(1)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!