zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    maven项目诡异的问题
    13) Developing Java Plugins
    15) maven dependency scope
    Bootstrap学习记录
    电力
    MongoDB学习记录
    Java基础知识
    旅游
    人生感悟
    【转】25岁到55岁:如何规划人生最重要的三个十年
  • 原文地址:https://www.cnblogs.com/djq-jone/p/10830947.html
Copyright © 2011-2022 走看看