Mybatis 批量更新

学习资源:https://blog.csdn.net/xyjawq1/article/details/74129316

<!-- 批量更新模板 -->
<update id="updateBatch" parameterType="java.util.List">
update bc_product_combo
<trim prefix="set" suffixOverrides=",">
  <trim prefix="user_id =case" suffix="end,">
    <foreach collection="list" item="item" index="index">
      <if test="item.userId != null" >
        when id=#{item.id} then #{item.userId,jdbcType=CHAR}
      </if>
    </foreach>
  </trim>
  <trim prefix="user_name =case" suffix="end,">
    <foreach collection="list" item="item" index="index">
      <if test="item.userName != null" >
        when id=#{item.id} then #{item.userName,jdbcType=VARCHAR}
      </if>
    </foreach>
  </trim>

</trim>
<where>
  id in
  <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
    #{item.id,jdbcType=CHAR}
  </foreach>
</where>
</update>

posted @ 2018-04-20 09:26  Rage_Leila  阅读(185)  评论(0编辑  收藏  举报