From c3d764ec40038f9b0194afc652377035c4182847 Mon Sep 17 00:00:00 2001 From: Agent Date: Sun, 29 Mar 2026 15:22:44 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A2=9E=E5=8A=A0=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E6=8E=92=E6=9F=A5=E4=BF=9D=E5=AD=98=E5=B1=9E=E6=80=A7=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/building/controller/ProductController.java | 8 ++------ .../service/impl/CategoryAttributeServiceImpl.java | 8 ++++++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/example/building/controller/ProductController.java b/src/main/java/com/example/building/controller/ProductController.java index 669e867..3a36f4d 100644 --- a/src/main/java/com/example/building/controller/ProductController.java +++ b/src/main/java/com/example/building/controller/ProductController.java @@ -156,16 +156,12 @@ public class ProductController { @PostMapping("/categories/{categoryId}/attributes") public Result saveCategoryAttributes( @PathVariable String categoryId, - @RequestBody Map body, + @RequestBody List attributes, @RequestHeader(value = "X-User-Role", required = false) String role) { if (!"admin".equals(role)) { return Result.error("只有管理员可以操作"); } - List attrs = (List) body.get("attributes"); - if (attrs == null) { - attrs = (List) body.get("list"); - } - categoryAttributeService.saveAttributes(categoryId, attrs); + categoryAttributeService.saveAttributes(categoryId, attributes); return Result.success(); } diff --git a/src/main/java/com/example/building/service/impl/CategoryAttributeServiceImpl.java b/src/main/java/com/example/building/service/impl/CategoryAttributeServiceImpl.java index df87eb6..4d8fed3 100644 --- a/src/main/java/com/example/building/service/impl/CategoryAttributeServiceImpl.java +++ b/src/main/java/com/example/building/service/impl/CategoryAttributeServiceImpl.java @@ -30,6 +30,13 @@ public class CategoryAttributeServiceImpl implements CategoryAttributeService { @Override @Transactional public void saveAttributes(String categoryId, List attrs) { + System.out.println("=== saveAttributes called ==="); + System.out.println("categoryId: " + categoryId); + System.out.println("attrs size: " + (attrs != null ? attrs.size() : 0)); + if (attrs != null) { + attrs.forEach(a -> System.out.println(" attr: " + a.getName() + ", type=" + a.getAttrType() + ", unit=" + a.getUnit())); + } + // 删除旧属性 categoryAttributeMapper.delete(new LambdaQueryWrapper() .eq(CategoryAttribute::getCategoryId, categoryId)); @@ -44,6 +51,7 @@ public class CategoryAttributeServiceImpl implements CategoryAttributeService { categoryAttributeMapper.insert(attr); } } + System.out.println("=== saveAttributes done ==="); } @Override