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);