zoukankan      html  css  js  c++  java
  • SpringCloud Feign请求流文件

    Provider

    服务提供方接口返回流文件

     Consumer

    消费者接受方式为fegn.Response,下载:

    public ModelAndView getChecklistTree(HttpServletResponse servletResponse) {
            ModelAndView mv = new ModelAndView();
            mv.setView(new DownloadView());
    
            Response response = violationService.download();
            Response.Body body = response.body();
            Map<String, Collection<String>> headers = response.headers();
            InputStream fileInputStream = null;
            try {
                fileInputStream = body.asInputStream();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                IOUtils.closeQuietly(fileInputStream);
            }
            try {
                String filename = Optional.ofNullable(headers.get("filename11")).map(m -> m.stream().collect(Collectors.toList()).get(0))
                        .orElse(URLEncoder.encode("分红方案-每股股息.xlsx", "utf-8"));
                mv.addObject(DownloadView.EXPORT_FILE, fileInputStream);
                mv.addObject(DownloadView.EXPORT_FILE_NAME, filename);
                mv.addObject(DownloadView.EXPORT_FILE_TYPE, DownloadView.FILE_TYPE.XLSX);
                servletResponse.setHeader("fileName", filename);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
    
            return mv;
        }
  • 相关阅读:
    ssh配置调试的必杀技
    关于lua垃圾回收是否会执行__gc函数呢?
    lua技巧分享之保护执行
    Java访问Hbase
    详解mmseg
    相关query挖掘
    玩转游戏搜索
    JVM系列-常用参数
    Java批处理ExecutorService/CompletionService
    Java动态编译
  • 原文地址:https://www.cnblogs.com/LiuFqiang/p/15792776.html
Copyright © 2011-2022 走看看