微调了俩fileController避免冲突

This commit is contained in:
高子兴 2024-07-06 00:02:50 +08:00
parent 8728f7f454
commit 50bfce4b23
2 changed files with 5 additions and 5 deletions

View File

@ -17,7 +17,7 @@ import java.nio.file.Paths;
@RestController
@RequestMapping("/courses")
public class FileController {
public class CourseFileController {
private static final String UPLOAD_DIR = "uploads/";
@PostMapping("/upload")

View File

@ -15,12 +15,12 @@ import java.nio.file.Path;
import java.nio.file.Paths;
@RestController
@CrossOrigin // 如果前端和后端不在同一个域名或端口下需要启用跨域
public class FileController {
@RequestMapping("/news")
public class NewsFileController {
private static final String UPLOAD_DIR = "uploads/";
@PostMapping("/news/uploadPic")
@PostMapping("/uploadPic")
public ResponseEntity<UploadFileResponse> uploadFile(@RequestParam("file") MultipartFile file) {
if (file.isEmpty()) {
return new ResponseEntity<>(new UploadFileResponse("文件不能为空", null), HttpStatus.BAD_REQUEST);
@ -45,7 +45,7 @@ public class FileController {
}
}
@GetMapping("/news/files/{filename}")
@GetMapping("/files/{filename}")
public ResponseEntity<Resource> getFile(@PathVariable String filename) {
try {
Path filePath = Paths.get(UPLOAD_DIR).resolve(filename).normalize();