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类型,可以加以修改进行使用。

  • 相关阅读:
    循序渐进Linux 1:Linux的基本结构
    Django通过中间件实现登录验证demo
    Django中简单添加HTML、css、js等文件(非正规添加,适合小白)
    数据库之MySQL
    前端之JQuery
    核心编程之第一章正则表达式
    前端之JS
    python基础面试常见题
    前端之CSS
    前端之HTML
  • 原文地址:https://www.cnblogs.com/tv151579/p/2878405.html
Copyright © 2011-2022 走看看