Mybatis 批量更新

學習資源:http://www.javashuo.com/article/p-fvinnmyg-mh.htmljava

<!-- 批量更新模板 -->
<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>ide

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

相關文章
相關標籤/搜索