mybatis批量处理

1.批量插入
<insert id="insertRelaction" parameterType="java.util.List">
insert into app_product_relation ( product_id,application_id ) values 
<foreach collection="list" item="item" index="index" separator=",">
(#{item.proId} , #{item.appId})
</foreach>
</insert>
1.1.我看见有些人用到了
selectkey这个标签,但我目前没有使用过


2.批量删除
<delete id="getRelationId" parameterType="java.util.List">
       delete from app_server_relation where relation_id in  
    <foreach collection="list" item = "item" open="(" separator="," close=")">
    #{item}  
    </foreach>  
</delete>
2.1只根据传来的list集合数据循环迭代删除,字段只能有一个,目前我没找到能有多个字段的添加删除的。
app_server_relation 表名
relation_id 字段名
collection里表示类型,这里是array,还可以是list

idItem不用管,相当于一个变量


3.批量更新

  <update id="updateAmount" parameterType="java.util.List">
    UPDATE cacuq_goods_statistical SET
    month_sale=
    <foreach close="end" collection="list" item="item" index="index" separator=" " open="case sku">
      WHEN #{item.sku,jdbcType=VARCHAR} THEN #{item.monthSale,jdbcType=INTEGER}
    </foreach>
    ,count_sale=
    <foreach close="end" collection="list" item="item" index="index" separator=" " open="case sku">
      WHEN #{item.sku,jdbcType=VARCHAR} THEN #{item.countSale,jdbcType=INTEGER}
    </foreach>
    WHERE sku IN
    <foreach close=")" collection="list" item="item" index="index" separator="," open="(">
      #{item.sku,jdbcType=VARCHAR}
    </foreach>
  </update>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值