// 先把模板传到服务器上去 然后根据不同的id来下载模板 @ApiOperation(value = "下载双清单支撑情况模板") @GetMapping("/downloadKPI") @ResponseBody public Result downloadKPI(@RequestParam("id") String id, HttpServletResponse response){ Map<String, String> zipTemplate = zipService.getZipTemplate(id); if (zipTemplate == null){ return Result.build(1, "该资源库模板不存在"); } String title = zipTemplate.get("title"); String url = zipTemplate.get("url"); try { File file = new File(url); BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file)); byte[] buffer = new byte[bis.available()]; bis.read(buffer); bis.close(); //response.setContentType("application/octet-stream"); response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(title, "UTF-8")); OutputStream os = new BufferedOutputStream(response.getOutputStream()); os.write(buffer); os.flush(); os.close(); } catch (Exception e) { return Result.build(1, "下载失败"); } return Result.ok(); }
项目里我改造后的模板导出
最新推荐文章于 2024-09-04 22:05:18 发布