jar 内部可下载
文件在 resources/excelTemplate/下
@GetMapping("file") public ResponseEntity fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request) { InputStream is = null; try { response.reset(); is = new ClassPathResource(File.separator + "excelTemplate" + File.separator + fileName).getInputStream(); response.addHeader("Cache-Control", "no-cache, no-store, must-revalidate"); response.addHeader("charset", "utf-8"); response.addHeader("Pragma", "no-cache"); String encodeName = URLEncoder.encode(fileName, StandardCharsets.UTF_8.toString()); response.setHeader("Content-Disposition", "attachment; filename="" + encodeName + ""; filename*=utf-8''" + encodeName); IOUtils.copy(is, response.getOutputStream()); response.flushBuffer(); } catch (Exception e) { log.error("下载文件失败", e); } finally { IOUtils.closeQuietly(is); } return null; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)