微调了俩fileController避免冲突
This commit is contained in:
parent
8728f7f454
commit
50bfce4b23
@ -17,7 +17,7 @@ import java.nio.file.Paths;
|
|||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/courses")
|
@RequestMapping("/courses")
|
||||||
public class FileController {
|
public class CourseFileController {
|
||||||
private static final String UPLOAD_DIR = "uploads/";
|
private static final String UPLOAD_DIR = "uploads/";
|
||||||
|
|
||||||
@PostMapping("/upload")
|
@PostMapping("/upload")
|
||||||
@ -15,12 +15,12 @@ import java.nio.file.Path;
|
|||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@CrossOrigin // 如果前端和后端不在同一个域名或端口下,需要启用跨域
|
@RequestMapping("/news")
|
||||||
public class FileController {
|
public class NewsFileController {
|
||||||
|
|
||||||
private static final String UPLOAD_DIR = "uploads/";
|
private static final String UPLOAD_DIR = "uploads/";
|
||||||
|
|
||||||
@PostMapping("/news/uploadPic")
|
@PostMapping("/uploadPic")
|
||||||
public ResponseEntity<UploadFileResponse> uploadFile(@RequestParam("file") MultipartFile file) {
|
public ResponseEntity<UploadFileResponse> uploadFile(@RequestParam("file") MultipartFile file) {
|
||||||
if (file.isEmpty()) {
|
if (file.isEmpty()) {
|
||||||
return new ResponseEntity<>(new UploadFileResponse("文件不能为空", null), HttpStatus.BAD_REQUEST);
|
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) {
|
public ResponseEntity<Resource> getFile(@PathVariable String filename) {
|
||||||
try {
|
try {
|
||||||
Path filePath = Paths.get(UPLOAD_DIR).resolve(filename).normalize();
|
Path filePath = Paths.get(UPLOAD_DIR).resolve(filename).normalize();
|
||||||
Loading…
Reference in New Issue
Block a user