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