mybatis批量处理

来源:互联网 发布:人工智能的好处英文 编辑:程序博客网 时间:2024/05/22 07:59
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不用管,相当于一个变量
0 0
原创粉丝点击