• springcloud 返回流案例


    消费者(必须post请求)

       public void  exportDwzzExcel(@RequestBody String data,HttpServletRequest request, HttpServletResponse servletResponse){
    JSONObject json=JSONObject.parseObject(data); String dwzz_id=json.getString("dwzz_id");
    Response response1 = zfglService.exportDwzzExcel(servletResponse,dwzz_id); Response.Body body = response1.body(); InputStream fileInputStream = null; OutputStream outStream; try { String fileName = new String(("对外转账详情信息.xlsx").getBytes("utf-8"), "ISO-8859-1"); servletResponse.addHeader("Content-Disposition", "attachment;filename=" + fileName); servletResponse.setContentType("application/vnd.ms-excel;charset=gb2312");
    fileInputStream = body.asInputStream(); outStream = servletResponse.getOutputStream();
    /*File fosfile = new File("D:\test2.png"); if(!fosfile.exists()){ fosfile.createNewFile(); } FileOutputStream fos = new FileOutputStream(fosfile);*/
    byte[] bytes = new byte[1024]; int len = 0; while ((len = fileInputStream.read(bytes)) != -1) { //fos.write(bytes,0,len); outStream.write(bytes, 0, len); } //fos.close(); fileInputStream.close(); outStream.close(); outStream.flush(); } catch (Exception e) { } }

    熔断机制

    public Response exportDwzzExcel(HttpServletResponse response,String dwzz_id) {
        Response response1 = yhywClient.exportDwzzExcel(response,dwzz_id);
        return response1;
    }
    

    Feign

     @GetMapping("/zfgl/exportDwzzExcel")
        Response exportDwzzExcel(@RequestParam(value = "response") HttpServletResponse response,@RequestParam(value = "dwzz_id") String dwzz_id);

    生产者

        public void exportDwzzExcel( HttpServletResponse response,String dwzz_id) throws Exception {
    
           /* File file = new File("F:\小憩\Map.png");
            InputStream fileInputStream = new FileInputStream(file);
            System.out.println(fileInputStream.available());
            OutputStream outStream;
            try {
                outStream = response.getOutputStream();
                File fosfile = new File("D:\test.png");
                if(!fosfile.exists()){
                    fosfile.createNewFile();
                }
                FileOutputStream fos = new FileOutputStream(fosfile);
                byte[] bytes = new byte[1024];
                int len = 0;
                while ((len = fileInputStream.read(bytes)) != -1) {
                    fos.write(bytes,0,len);
                    outStream.write(bytes, 0, len);
                }
                fileInputStream.close();
                fos.close();
    
                outStream.close();
                outStream.flush();
                System.out.println(outStream);
            } catch (IOException e) {
                e.printStackTrace();
            }*/
    HSSFWorkbook workbook=null; try { workbook = zfglService.exportDwzzExcel(dwzz_id); try { //workbook将Excel写入到response的输出流中,供页面下载 OutputStream os = response.getOutputStream(); workbook.write(os); if(workbook!=null){ workbook.close(); } if(os!=null){ os.close(); os.flush(); } } catch (Exception e) { e.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); } }

      

     

      

  • 相关阅读:
    文件权限
    函数指针
    位操作
    宏定义
    GNU gcc常用编译选项
    SHELL编程(六)---------数组和函数
    26.使用中间件的方式包装日志输出
    25.最基本的日志输出方式,内置日志包使用
    24.把熔断器整合到我们的客户端代码中(初步)
    23.熔断器学习,熔断器的三种状态,状态获取
  • 原文地址:https://www.cnblogs.com/jrkl/p/14340332.html
Copyright © 2020-2023  润新知