M y b a t i s批量添加

  insert into USER_ROLE_AUT 
    (RU_ID,RU_ROLE_ID, RU_AUT_ID, RU_TIME_INS, RU_USER_INS, RU_TIME_LST, RU_USER_LST, RU_STATUS) 
        select U.* from USER_ROLE_AUT
     ( <foreach collection="maps" item="item" index="index" separator="union all" >  
         select
                RU_ID_SEQ.Nextval,
                #{item.ruRoleId,jdbcType=DECIMAL}, 
                #{item.ruAutId,jdbcType=DECIMAL}, 
                #{item.ruTimeIns,jdbcType=TIMESTAMP}, 
                #{item.ruUserIns,jdbcType=VARCHAR}, 
                #{item.ruTimeLst,jdbcType=TIMESTAMP}, 
                 #{item.ruUserLst,jdbcType=VARCHAR},
                  #{item.ruStatus,jdbcType=DECIMAL}
        from USER_ROLE_AUT
    </foreach>
    )U  

帮忙看看有没有写错

3个回答

values呢?还有新增还能查询?

qq_22948413
qq_22948413 你会用Mybatis吗
4 年多之前 回复

这是我写的批量插入,

 <insert id="insertSelective" useGeneratedKeys="true" parameterType="java.util.List">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <selectKey keyProperty="id" order="BEFORE" resultType="java.math.BigDecimal">
      select DISCOUNT_COUPON_PERSON_SEQ.NEXTVAL from DUAL
    </selectKey>
    insert into T_DISCOUNT_COUPON_PERSON
     ( ID,
        USER_ID,
        COUPON_ID,
        ORDER_SHOP_ID,
        COUPON_GET_WAY,
        COUPON_GET_CHANNEL,
        COUPON_GET_DATE,
        COUPON_USE_DATE,
        MONEY_BACK_APPLY_DATE,
        COUPON_USE_STATUS,
        CANCEL_LOCK_REASON,
        CREATE_TIME,
        MODIFY_TIME)
        select logsaccessseq.NEXTVAL,a.* from (
        <foreach collection="list" item="item" index="index"
            separator="union all">
            select
            #{item.userId,jdbcType=DECIMAL} as userId,
            #{item.couponId,jdbcType=VARCHAR} as couponId,#{item.orderShopId,jdbcType=VARCHAR} as orderShopId,#{item.couponGetWay,jdbcType=VARCHAR} as couponGetWay,
            #{item.couponGetChannel,jdbcType=VARCHAR} as couponGetChannel,#{item.couponGetDate,jdbcType=TIMESTAMP} as couponGetDate,#{item.couponUseDate,jdbcType=TIMESTAMP} as couponUseDate,
            #{item.moneyBackApplyDate,jdbcType=TIMESTAMP} as moneyBackApplyDate,#{item.couponUseStatus,jdbcType=VARCHAR} as couponUseStatus,#{item.cancelLockReason,jdbcType=VARCHAR} as cancelLockReason,
            #{item.createTime,jdbcType=TIMESTAMP} as createTime,#{item.modifyTime,jdbcType=TIMESTAMP} as modifyTime
            from dual
        </foreach>
        ) a
  </insert>


改成

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问