mybatis中批量插入与批量更新

博客主要介绍了MyBatis对MySQL数据库进行批量插入和更新的操作。给出了批量插入和批量更新的代码示例,指出批量插入的separator为逗号,批量更新的separator为分号,其他方面差异不大。

批量插入:

<insert id="insertBatch" parameterType="java.util.List">
   insert into order_promotion_details (pmt_id, promotion_name, promotion_fee, 
      promotion_desc, promotion_id, gift_item_id, 
      gift_item_name, gift_item_num, pmt_type, 
      update_time, create_time)
    values 
     <foreach collection="list" item="item" index="index" separator="," >
    (#{item.pmtId,jdbcType=VARCHAR}, #{item.promotionName,jdbcType=VARCHAR}, #{item.promotionFee,jdbcType=REAL}, 
 #{item.promotionDesc,jdbcType=VARCHAR}, #{item.promotionId,jdbcType=VARCHAR}, #{item.giftItemId,jdbcType=VARCHAR}, 
      #{item.giftItemName,jdbcType=VARCHAR}, #{item.giftItemNum,jdbcType=INTEGER}, #{item.pmtType,jdbcType=VARCHAR}, 
      #{item.updateTime,jdbcType=TIMESTAMP}, #{item.createTime,jdbcType=TIMESTAMP})
    </foreach>
  </insert>

 

批量更新:


<update id="updateBatch" parameterType="java.util.List">
      <foreach collection="list" item="item" index="index" separator=";" >
      UPDATE order_source
    SET
        lastmodify =#{item.lastmodify},
        update_time=#{item.updateTime}
    WHERE order_id=#{item.orderId}
    </foreach>
</update>

批量插入的separator是逗号,批量更新的separator是分号;其他的没有太大区别

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值