mybatis批量更新

List<TbDepartment>将整个集合的对象根据对应的ID进行更新到tb_department表。

mapper.xml
<!-- 批量更新After表数据 -->
<update id="updateBatch"  parameterType="java.util.List">
   update TB_DEPARTMENT 
   <trim prefix="set" suffixOverrides=",">
      <trim prefix="s1 = case" suffix="end,">
      <foreach collection="list" item="i" index="index">
        when id=#{i.id,jdbcType=INTEGER} then #{i.s1,jdbcType=VARCHAR}
      </foreach>
      </trim>
      <trim prefix="s2 = case" suffix="end,">
      <foreach collection="list" item="i" index="index">
        when id=#{i.id,jdbcType=INTEGER} then #{i.s2,jdbcType=VARCHAR}
      </foreach>
      </trim>      
      <trim prefix="s3 = case" suffix="end,">
      <foreach collection="list" item="i" index="index">
        when id=#{i.id,jdbcType=INTEGER} then #{i.s3,jdbcType=VARCHAR}
      </foreach>
      </trim>
   </trim>
   where
   <foreach collection="list" separator="or" item="i" index="index" >
       id=#{i.id,jdbcType=INTEGER}
   </foreach>
</update>


java调用代码:
List<TbDepartment> list = new ArrayList<TbDepartment>();
sqlSessionTemplate.update("updateBatch", list);

你可能感兴趣的:(java,oracle)