Просмотр исходного кода

fix: SupplyManageController detail/update/delete robust id parsing

ClassCastException was thrown when request body id arrived as a
JSON string rather than a number. Added type-safe parsing that
handles both Number and String id values across the supplier
management endpoints.

Co-authored-by: Sisyphus <sisyphus@omo.codes>
Sisyphus 2 месяцев назад
Родитель
Сommit
f7899d1871

+ 8 - 2
cfc-backend/src/main/java/com/etotem/cfc/controller/admin/SupplyManageController.java

@@ -69,7 +69,13 @@ public class SupplyManageController {
      */
     @PostMapping("/detail")
     public Result<User> detail(@RequestBody Map<String, Object> params) {
-        Long id = params.get("id") != null ? ((Number) params.get("id")).longValue() : null;
+        Object rawId = params.get("id");
+        Long id = null;
+        if (rawId instanceof Number) {
+            id = ((Number) rawId).longValue();
+        } else if (rawId instanceof String) {
+            try { id = Long.parseLong((String) rawId); } catch (NumberFormatException ignored) {}
+        }
         if (id == null) {
             return Result.error("id不能为空");
         }
@@ -77,7 +83,7 @@ public class SupplyManageController {
         if (user == null) {
             return Result.error("供应商不存在");
         }
-        user.setPassword(null); // 清除密码
+        user.setPassword(null);
         return Result.success(user);
     }