mybatis 批量更新

在实际的开发中, 存在一次性插入很多数据,和更新很多数据的情况;

mysql+Mybatis

一.Mybatis批量更新

 1 <update id="batchUpdateByIds" parameterType="list">
 2         update crm_member
 3         <trim prefix="set" suffixOverrides=",">
 4             <trim prefix="type =case" suffix="end,">
 5                 <foreach collection="list" item="item" index="index">
 6                     <if test="item.type !=null">
 7                         when id=#{item.id} then #{item.type}
 8                     </if>
 9                 </foreach>
10             </trim>
11             <trim prefix="update_by =case" suffix="end,">
12                 <foreach collection="list" item="item" index="index">
13                     <if test="item.updateBy !=null and item.updateBy != ''">
14                         when id=#{item.id} then #{item.updateBy}
15                     </if>
16                 </foreach>
17             </trim>
18             <trim prefix="update_time =case" suffix="end,">
19                 <foreach collection="list" item="item" index="index">
20                     <if test="item.updateTime !=null">
21                         when id=#{item.id} then #{item.updateTime}
22                     </if>
23                 </foreach>
24             </trim>
25             <trim prefix="follow_status =case" suffix="end,">
26                 <foreach collection="list" item="item" index="index">
27                     <if test="item.followStatus !=null">
28                         when id=#{item.id} then #{item.followStatus}
29                     </if>
30                 </foreach>
31             </trim>
32         </trim>
33         where id in
34         <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
35             #{item.id}
36         </foreach>
37     </update>

 

posted @ 2019-05-08 11:45  远启  阅读(582)  评论(0编辑  收藏  举报