diff --git a/doc/db_table.md b/doc/db_table.md index d5af503..8653414 100644 --- a/doc/db_table.md +++ b/doc/db_table.md @@ -12,6 +12,7 @@ | ---- | -------- | -------- | ---- | | id | bigint | primary key; identity | 文件id | | file_path | varchar | not null | 文件路径 | +| url_path | varchar | not null | 访问路径 | # 论文 sys_paper diff --git a/src/main/java/com/bupt/note/Controller/FileController.java b/src/main/java/com/bupt/note/Controller/FileController.java index 129cc94..4dc2475 100644 --- a/src/main/java/com/bupt/note/Controller/FileController.java +++ b/src/main/java/com/bupt/note/Controller/FileController.java @@ -54,6 +54,7 @@ public class FileController { file.transferTo(txtFile); com.bupt.note.Model.File f=new com.bupt.note.Model.File(); f.setFilePath(txtFile.getAbsolutePath()); + f.setUrlPath("/txt/"+txtFile.getName()); fileRepository.save(f); return ResponseDataUtil.buildSuccess(f.getId()); } catch (IOException e) { @@ -66,6 +67,16 @@ public class FileController { } } + @GetMapping("find/{id}") + public ResponseData get(@PathVariable Long id){ + if(fileRepository.existsById(id)){ + com.bupt.note.Model.File file= fileRepository.getOne(id); + return ResponseDataUtil.buildSuccess(file.getUrlPath()); + }else{ + return ResponseDataUtil.buildError(); + } + } + /** * 删除论文文本文件 * @param id 文件id diff --git a/src/main/java/com/bupt/note/Model/File.java b/src/main/java/com/bupt/note/Model/File.java index 25c6dc5..cc04078 100644 --- a/src/main/java/com/bupt/note/Model/File.java +++ b/src/main/java/com/bupt/note/Model/File.java @@ -11,6 +11,7 @@ public class File { private Long Id; private String filePath; + private String urlPath; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -31,4 +32,12 @@ public class File { this.filePath = filePath; } + @Column(nullable = false) + public String getUrlPath() { + return urlPath; + } + + public void setUrlPath(String urlPath) { + this.urlPath = urlPath; + } }