微调了俩fileController避免冲突
This commit is contained in:
parent
8728f7f454
commit
50bfce4b23
@ -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")
|
||||
@ -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();
|
||||
Loading…
Reference in New Issue
Block a user