mybatis 批量更新

摘抄自:https://blog.csdn.net/LQQianLee/article/details/79771618

    

二、批量更新——单条件

  1.  
    <update id="update" parameterType="java.util.List">
  2.  
    update nt_menu
  3.  
    <trim prefix="set" suffixOverrides=",">
  4.  
    <trim prefix="breakfast =case" suffix="end,">
  5.  
    <foreach collection="list" item="cus">
  6.  
    <if test="cus.breakfast != null">
  7.  
    when menuId=#{cus.menuId} then #{cus.breakfast}
  8.  
    </if>
  9.  
    </foreach>
  10.  
    </trim>
  11.  
    <trim prefix="lunch =case" suffix="end,">
  12.  
    <foreach collection="list" item="cus">
  13.  
    <if test="cus.lunch != null">
  14.  
    when menuId=#{cus.menuId} then #{cus.lunch}
  15.  
    </if>
  16.  
    </foreach>
  17.  
    </trim>
  18.  
    <trim prefix="dinner =case" suffix="end,">
  19.  
    <foreach collection="list" item="cus">
  20.  
    <if test="cus.dinner != null">
  21.  
    when menuId=#{cus.menuId} then #{cus.dinner}
  22.  
    </if>
  23.  
    </foreach>
  24.  
    </trim>
  25.  
    <trim prefix="modifier =case" suffix="end,">
  26.  
    <foreach collection="list" item="cus">
  27.  
    <if test="cus.modifier != null">
  28.  
    when menuId=#{cus.menuId} then #{cus.modifier}
  29.  
    </if>
  30.  
    </foreach>
  31.  
    </trim>
  32.  
    </trim>
  33.  
    <where>
  34.  
    <foreach collection="list" separator="or" item="cus">
  35.  
    menuId=#{cus.menuId}
  36.  
    </foreach>
  37.  
    </where>
  38.  
    </update>

批量更新——多条件

原文地址:https://www.cnblogs.com/shujiying/p/14341875.html