diff --git a/backend/src/main/java/com/maternalmall/common/ApiResponse.java b/backend/src/main/java/com/maternalmall/common/ApiResponse.java index f24a2de..6a3a276 100644 --- a/backend/src/main/java/com/maternalmall/common/ApiResponse.java +++ b/backend/src/main/java/com/maternalmall/common/ApiResponse.java @@ -23,4 +23,8 @@ public class ApiResponse { public static ApiResponse fail(String message) { return new ApiResponse<>(-1, message, null); } + + public static ApiResponse fail(String message, Class clazz) { + return new ApiResponse<>(-1, message, null); + } } diff --git a/backend/src/main/java/com/maternalmall/controller/FileUploadController.java b/backend/src/main/java/com/maternalmall/controller/FileUploadController.java index b2ecd3f..09bf48e 100644 --- a/backend/src/main/java/com/maternalmall/controller/FileUploadController.java +++ b/backend/src/main/java/com/maternalmall/controller/FileUploadController.java @@ -25,7 +25,7 @@ public class FileUploadController { @PostMapping("/upload") public ApiResponse uploadFile(@RequestParam("file") MultipartFile file) { if (file.isEmpty()) { - return ApiResponse.fail("请选择要上传的文件"); + return ApiResponse.fail("请选择要上传的文件", String.class); } try { @@ -52,20 +52,20 @@ public class FileUploadController { return ApiResponse.ok(fileUrl); } catch (IOException e) { - return ApiResponse.fail("文件上传失败: " + e.getMessage()); + return ApiResponse.fail("文件上传失败: " + e.getMessage(), String.class); } } @PostMapping("/upload/image") public ApiResponse uploadImage(@RequestParam("file") MultipartFile file) { if (file.isEmpty()) { - return ApiResponse.fail("请选择要上传的图片"); + return ApiResponse.fail("请选择要上传的图片", String.class); } // 检查文件类型 String contentType = file.getContentType(); if (contentType == null || !contentType.startsWith("image/")) { - return ApiResponse.fail("只能上传图片文件"); + return ApiResponse.fail("只能上传图片文件", String.class); } return uploadFile(file);