Commit 562f4cb953bccd1b4be474441e5e36011941b945
1 parent
7089ef76
根据艿艿的提示修改
Showing
1 changed file
with
10 additions
and
15 deletions
src/main/java/cn/iocoder/dashboard/modules/infra/controller/doc/InfDbDocController.java
| ... | ... | @@ -48,9 +48,7 @@ public class InfDbDocController { |
| 48 | 48 | |
| 49 | 49 | @GetMapping("/export-html") |
| 50 | 50 | @ApiOperation("导出html格式的数据文档") |
| 51 | - @ApiImplicitParams({ | |
| 52 | - @ApiImplicitParam(name = "deleteFile", value = "是否删除在服务器本地生成的数据库文档", example = "true", dataTypeClass = Boolean.class), | |
| 53 | - }) | |
| 51 | + @ApiImplicitParam(name = "deleteFile", value = "是否删除在服务器本地生成的数据库文档", example = "true", dataTypeClass = Boolean.class) | |
| 54 | 52 | public void exportHtml(@RequestParam(defaultValue = "true") Boolean deleteFile, |
| 55 | 53 | HttpServletResponse response) throws IOException { |
| 56 | 54 | doExportFile(EngineFileType.HTML, deleteFile, response); |
| ... | ... | @@ -58,9 +56,7 @@ public class InfDbDocController { |
| 58 | 56 | |
| 59 | 57 | @GetMapping("/export-word") |
| 60 | 58 | @ApiOperation("导出word格式的数据文档") |
| 61 | - @ApiImplicitParams({ | |
| 62 | - @ApiImplicitParam(name = "deleteFile", value = "是否删除在服务器本地生成的数据库文档", example = "true", dataTypeClass = Boolean.class), | |
| 63 | - }) | |
| 59 | + @ApiImplicitParam(name = "deleteFile", value = "是否删除在服务器本地生成的数据库文档", example = "true", dataTypeClass = Boolean.class) | |
| 64 | 60 | public void exportWord(@RequestParam(defaultValue = "true") Boolean deleteFile, |
| 65 | 61 | HttpServletResponse response) throws IOException { |
| 66 | 62 | doExportFile(EngineFileType.WORD, deleteFile, response); |
| ... | ... | @@ -68,9 +64,7 @@ public class InfDbDocController { |
| 68 | 64 | |
| 69 | 65 | @GetMapping("/export-markdown") |
| 70 | 66 | @ApiOperation("导出markdown格式的数据文档") |
| 71 | - @ApiImplicitParams({ | |
| 72 | - @ApiImplicitParam(name = "deleteFile", value = "是否删除在服务器本地生成的数据库文档", example = "true", dataTypeClass = Boolean.class), | |
| 73 | - }) | |
| 67 | + @ApiImplicitParam(name = "deleteFile", value = "是否删除在服务器本地生成的数据库文档", example = "true", dataTypeClass = Boolean.class) | |
| 74 | 68 | public void exportMarkdown(@RequestParam(defaultValue = "true") Boolean deleteFile, |
| 75 | 69 | HttpServletResponse response) throws IOException { |
| 76 | 70 | doExportFile(EngineFileType.MD, deleteFile, response); |
| ... | ... | @@ -81,12 +75,13 @@ public class InfDbDocController { |
| 81 | 75 | String docFileName = DOC_FILE_NAME + "_" + IdUtil.fastSimpleUUID(); |
| 82 | 76 | String filePath = doExportFile(fileOutputType, docFileName); |
| 83 | 77 | String downloadFileName = DOC_FILE_NAME + fileOutputType.getFileSuffix(); //下载后的文件名 |
| 84 | - // 读取,返回 | |
| 85 | - //IoUtil.readBytes 直接读取FileInputStream 不会关闭流,有bug,所以用BufferedInputStream包装一下, 关闭流后才能删除文件 | |
| 86 | - byte[] content = IoUtil.readBytes(new BufferedInputStream(new FileInputStream(filePath))); | |
| 87 | - //这里不用hutool工具类,它的中文文件名编码有问题,导致在浏览器下载时有问题 | |
| 88 | - ServletUtils.writeAttachment(response, downloadFileName, content); | |
| 89 | - handleDeleteFile(deleteFile, filePath); | |
| 78 | + try { | |
| 79 | + // 读取,返回 | |
| 80 | + //这里不用hutool工具类,它的中文文件名编码有问题,导致在浏览器下载时有问题 | |
| 81 | + ServletUtils.writeAttachment(response, downloadFileName, FileUtil.readBytes(filePath)); | |
| 82 | + }finally { | |
| 83 | + handleDeleteFile(deleteFile, filePath); | |
| 84 | + } | |
| 90 | 85 | } |
| 91 | 86 | |
| 92 | 87 | /** | ... | ... |