zoukankan      html  css  js  c++  java
  • spring mvc 输出流

    @RequestMapping(value = "/reportTemplate/{id}/content", method = RequestMethod.GET)
    public ResponseEntity<byte[]> downloadReportTemplateContent(
            @PathVariable("id") final ReportTemplate reportTemplate)
            throws IOException {
        ReportDatei file = reportTemplate.getFile();
    
        String fileName = reportTemplate.getName() + EXCEL_FILE_NAME_ENDING;
        HttpHeaders responseHeaders = httpHeaderExcelFileAttachment(fileName,
                                        datei.getDaten().length);
        return new ResponseEntity<byte[]>(file.getDataArray(),
                                          responseHeaders, HttpStatus.OK);
    }
    
    
    public static HttpHeaders httpHeaderExcelFileAttachment(final String fileName,
            final int fileSize) {
        String encodedFileName = fileName.replace('"', ' ').replace(' ', '_');
    
        HttpHeaders responseHeaders = new HttpHeaders();
        responseHeaders.setContentType(MediaType.parseMediaType("application/vnd.ms-excel"));
        responseHeaders.setContentLength(fileSize);
        responseHeaders.set("Content-Disposition", "attachment");
        responseHeaders.add("Content-Disposition", "filename=\"" + encodedFileName + '\"');
        return responseHeaders;
    }

     转自:http://blog.163.com/sir_876/blog/#m=0&t=1&c=fks_087068086087085070085086095095085087086067081084084064

    以上的输出格式为excel类型,可以加以修改进行使用。

  • 相关阅读:
    dede首页调用分类信息
    install sphinx
    rails新环境
    互联网创业三件事:钱、人和项目
    Remove Duplicate Elements from an Array using jQuery
    rails新环境
    rails新环境
    牛人
    电动车电池
    rails新环境
  • 原文地址:https://www.cnblogs.com/tv151579/p/2878405.html
Copyright © 2011-2022 走看看