@RequestMapping(value = "/files/{file_name}", method = RequestMethod.GET)public void getFile( @PathVariable("file_name") String fileName, HttpServletResponse response) { try { // get your file as InputStream InputStream is = ...; // copy it to response's OutputStream org.apache.commons.io.IOUtils.copy(is, response.getOutputStream()); response.flushBuffer(); } catch (IOException ex) { log.info("Error writing file to output stream. Filename was '{}'", fileName, ex); throw new RuntimeException("IOError writing file to output stream"); }}一般来说,当你拥有时
response.getOutputStream(),你可以在其中编写任何内容。你可以将此输出流作为将生成的PDF放置到生成器的地方。另外,如果你知道要发送的文件类型,则可以设置
response.setContentType("application/pdf");


