mybatis批量处理

mybatis 批量插入和更新

1.insert

1
2
3
4
5
6
7
8
9
10
11
<insert id="insertBatch" parameterType="java.util.List">
insert into sg_gkzb_pre_win_bid_detail (batch_id, batch_name, batch_code,
divide_bid_id,divide_bid_code,divide_bid_name,package_id,package_code,package_name,
supply_bid_id,supply_bid_person,is_calculated,approve_status)
values
<foreach collection="list" item="item" index="index" separator="," >
(#{item.batchId},#{item.batchName},#{item.batchCode},#{item.divideBidId},
#{item.divideBidCode},#{item.divideBidName},#{item.packageId},#{item.packageCode},
#{item.packageName},#{item.supplyBidId},#{item.supplyBidPerson},#{item.isCalculated},#{item.approveStatus})
</foreach>
</insert>

2.update

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<update id="updateBatch" parameterType="java.util.List">
update sg_gkzb_pre_win_bid_detail set
tech_score=
<foreach collection="list" item="item" index="index" separator=" " open="case supply_bid_id" close="end">
when #{item.supplyBidId} then #{item.techScore}
</foreach>
,business_score=
<foreach collection="list" item="item" index="index" separator=" " open="case supply_bid_id" close="end">
when #{item.supplyBidId} then #{item.businessScore}
</foreach>
,price_score=
<foreach collection="list" item="item" index="index" separator=" " open="case supply_bid_id" close="end">
when #{item.supplyBidId} then #{item.priceScore}
</foreach>
,is_submit=
<foreach collection="list" item="item" index="index" separator=" " open="case supply_bid_id" close="end">
when #{item.supplyBidId} then #{item.isSubmit}
</foreach>
where supply_bid_id in
<foreach collection="list" item="item" index="index"
separator="," open="(" close=")">

#{item.supplyBidId}
</foreach>
</update>