| | |
| | | |
| | | @GetMapping("/download/{resGuid}") |
| | | public ResponseEntity genera(HttpServletResponse response, @PathVariable String resGuid) throws Exception { |
| | | TbWordVO tbWordVO = sjztmdService.getTbWordVO(resGuid); |
| | | HashMap<String,Object> obj = sjztmdService.getTbWordVO(resGuid); |
| | | |
| | | TbWordVO tbWordVO = (TbWordVO) obj.get("tbWordVO"); |
| | | Map<String,Object> tableMap= (Map<String, Object>) obj.get("tableMap"); |
| | | |
| | | String fileName = resGuid + ".docx"; |
| | | byte[] data = WordUtil.compileTemplateAndRenderData(tbWordVO); |
| | | byte[] data = WordUtil.compileTemplateAndRenderData(tbWordVO,tableMap); |
| | | |
| | | // 创建响应实体并设置响应头,将输出流作为响应体返回给客户端 |
| | | InputStreamResource resource = new InputStreamResource(new ByteArrayInputStream(data)); |
| | |
| | | |
| | | // 将临时文件添加到响应中,以便用户下载 |
| | | return ResponseEntity.ok() |
| | | .contentType(MediaType.APPLICATION_OCTET_STREAM) // 设置响应的内容类型为二进制流(octet stream) |
| | | .contentType(MediaType.valueOf("application/vnd.openxmlformats-officedocument.wordprocessingml.document")) // 设置响应的内容类型为二进制流(octet stream) |
| | | .header("Content-Disposition", "attachment; filename=\"" + fileNameURL) // 设置响应的Content-Disposition头,以便浏览器提示用户下载文件 |
| | | .body(resource); // 将InputStreamResource对象作为响应体 |
| | | } |