Lijy 6 tháng trước cách đây
mục cha
commit
198d7066b2

+ 12 - 3
fhKeeper/formulahousekeeper/ArticleOperation/src/main/java/com/my/bigevent/controller/CategoryController.java

@@ -4,7 +4,6 @@ import com.my.bigevent.pojo.Category;
 import com.my.bigevent.pojo.Result;
 import com.my.bigevent.service.CategoryService;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
@@ -22,7 +21,7 @@ public class CategoryController
      * @return
      */
     @PostMapping
-    public Result add(@RequestBody @Validated Category category)
+    public Result add(@RequestBody Category category)
     {
         return categoryService.add(category);
     }
@@ -44,8 +43,18 @@ public class CategoryController
      * @return
      */
     @PutMapping                       //指定分组校验中的 Update.class 分组进行校验
-    public Result update(@RequestBody @Validated(Category.Update.class) Category category)
+    public Result update(@RequestBody Category category)
     {
+        if(null==category.getCategoryName()||category.getCategoryName().isEmpty()){
+            return Result.error("分类名称不能为空");
+        }
+        if(null==category.getCategoryAlias()||category.getCategoryAlias().isEmpty()){
+            return Result.error("分类别名不能为空");
+        }
+        Integer count=categoryService.selectCountByNameWithoutSelf(category);
+        if(count>0){
+            return Result.error("标签名称重复");
+        }
         categoryService.update(category);
         return Result.success("更新文章分类成功!");
     }

+ 2 - 0
fhKeeper/formulahousekeeper/ArticleOperation/src/main/java/com/my/bigevent/mapper/CategoryMapper.java

@@ -29,4 +29,6 @@ public interface CategoryMapper
     Integer selectCountByName(String categoryName);
     @Select("select * from category")
     List<Category> getAllList();
+    @Select("select count(*) from category where category_name=#{categoryName} and id != #{id}")
+    Integer selectCountByNameWithoutSelf(Category category);
 }

+ 2 - 0
fhKeeper/formulahousekeeper/ArticleOperation/src/main/java/com/my/bigevent/service/CategoryService.java

@@ -17,4 +17,6 @@ public interface CategoryService
 
 
     Integer selectArticleCountByCategoryId(String id);
+
+    Integer selectCountByNameWithoutSelf(Category category);
 }

+ 5 - 0
fhKeeper/formulahousekeeper/ArticleOperation/src/main/java/com/my/bigevent/service/impl/CategoryServiceImpl.java

@@ -72,4 +72,9 @@ public class CategoryServiceImpl implements CategoryService
     public Integer selectArticleCountByCategoryId(String id) {
         return categoryMapper.selectArticleCountByCategoryId(id);
     }
+
+    @Override
+    public Integer selectCountByNameWithoutSelf(Category category) {
+        return categoryMapper.selectCountByNameWithoutSelf(category);
+    }
 }

+ 3 - 9
fhKeeper/formulahousekeeper/webttkuaiban/src/main/resources/templates/knowledge.ftl

@@ -87,18 +87,12 @@
 <script src="/js/iframe.js"></script>
 
 <script>
-  // 获取当前页面的 URL 参数
-  const params = new URLSearchParams(window.location.search);
 
   // 将参数转换为一个对象
-  const paramObj = {};
-  params.forEach((value, key) => {
-    paramObj[key] = value;
-  });
-
+  const params = new URLSearchParams(window.location.search);
+  const pageIndex = +params.get('pageIndex') || 1;
+  const pageSize = +params.get('pageSize') || 10;
   // 获取当前页面地址的参数
-  const { pageIndex = 1, pageSize = 10 } = params;
-
   let total = ${total}
   let totalPages = Math.ceil(total / pageSize); // 总页数
   let currentSize = pageSize;