diff --git a/spzx-common/common-util/src/main/java/com/atguigu/constant/MessageConstant.java b/spzx-common/common-util/src/main/java/com/atguigu/constant/MessageConstant.java index 7d96c14..18c16f6 100644 --- a/spzx-common/common-util/src/main/java/com/atguigu/constant/MessageConstant.java +++ b/spzx-common/common-util/src/main/java/com/atguigu/constant/MessageConstant.java @@ -20,4 +20,5 @@ public class MessageConstant { public static final String UPDATE_ID_IS_NOT_EMPTY = "删除id不能为空"; public static final String DELETE_ID_IS_NOT_EMPTY = "修改id不能为空"; public static final String MENU_IS_NOT_EXIST = "菜单不存在"; + public static final String SAVE_DTO_IS_NULL = "添加参数不能为空"; } diff --git a/spzx-manager/src/main/java/com/atguigu/spzx/manger/controller/CategoryBrandController.java b/spzx-manager/src/main/java/com/atguigu/spzx/manger/controller/CategoryBrandController.java index 9ccfeb0..49d1339 100644 --- a/spzx-manager/src/main/java/com/atguigu/spzx/manger/controller/CategoryBrandController.java +++ b/spzx-manager/src/main/java/com/atguigu/spzx/manger/controller/CategoryBrandController.java @@ -8,10 +8,7 @@ import com.github.pagehelper.PageInfo; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @Tag(name = "分类品牌") @RestController @@ -26,4 +23,11 @@ public class CategoryBrandController { PageInfo pageInfo = categoryBrandService.findByPage(page, limit, dto); return Result.success(pageInfo); } + + @Operation(summary = "添加功能", description = "添加功能") + @PostMapping("save") + public Result save(@RequestBody CategoryBrand categoryBrand) { + categoryBrandService.save(categoryBrand); + return Result.success(); + } } \ No newline at end of file diff --git a/spzx-manager/src/main/java/com/atguigu/spzx/manger/mapper/CategoryBrandMapper.java b/spzx-manager/src/main/java/com/atguigu/spzx/manger/mapper/CategoryBrandMapper.java index a72adea..e3e9006 100644 --- a/spzx-manager/src/main/java/com/atguigu/spzx/manger/mapper/CategoryBrandMapper.java +++ b/spzx-manager/src/main/java/com/atguigu/spzx/manger/mapper/CategoryBrandMapper.java @@ -15,4 +15,11 @@ public interface CategoryBrandMapper { * @return PageInfo */ List findByPage(CategoryBrandDto dto); + + /** + * 添加功能 + * + * @param categoryBrand 分类品牌实体类 + */ + void save(CategoryBrand categoryBrand); } diff --git a/spzx-manager/src/main/java/com/atguigu/spzx/manger/service/CategoryBrandService.java b/spzx-manager/src/main/java/com/atguigu/spzx/manger/service/CategoryBrandService.java index 2b8231d..da2b1f3 100644 --- a/spzx-manager/src/main/java/com/atguigu/spzx/manger/service/CategoryBrandService.java +++ b/spzx-manager/src/main/java/com/atguigu/spzx/manger/service/CategoryBrandService.java @@ -14,4 +14,11 @@ public interface CategoryBrandService { * @return PageInfo */ PageInfo findByPage(Integer page, Integer limit, CategoryBrandDto dto); + + /** + * 添加功能 + * + * @param categoryBrand 分类品牌实体类 + */ + void save(CategoryBrand categoryBrand); } diff --git a/spzx-manager/src/main/java/com/atguigu/spzx/manger/service/impl/CategoryBrandServiceImpl.java b/spzx-manager/src/main/java/com/atguigu/spzx/manger/service/impl/CategoryBrandServiceImpl.java index 289b213..4f42d74 100644 --- a/spzx-manager/src/main/java/com/atguigu/spzx/manger/service/impl/CategoryBrandServiceImpl.java +++ b/spzx-manager/src/main/java/com/atguigu/spzx/manger/service/impl/CategoryBrandServiceImpl.java @@ -1,5 +1,7 @@ package com.atguigu.spzx.manger.service.impl; +import com.atguigu.constant.MessageConstant; +import com.atguigu.exception.BunnyException; import com.atguigu.spzx.manger.mapper.CategoryBrandMapper; import com.atguigu.spzx.manger.service.CategoryBrandService; import com.atguigu.spzx.model.dto.product.CategoryBrandDto; @@ -30,4 +32,17 @@ public class CategoryBrandServiceImpl implements CategoryBrandService { List categoryBrandList = categoryBrandMapper.findByPage(dto); return new PageInfo<>(categoryBrandList); } + + /** + * 添加功能 + * + * @param categoryBrand 分类品牌实体类 + */ + @Override + public void save(CategoryBrand categoryBrand) { + if (categoryBrand == null) { + throw new BunnyException(MessageConstant.SAVE_DTO_IS_NULL); + } + categoryBrandMapper.save(categoryBrand); + } } diff --git a/spzx-manager/src/main/resources/mapper/CategoryBrandMapper .xml b/spzx-manager/src/main/resources/mapper/CategoryBrandMapper .xml index 7611219..003dc47 100644 --- a/spzx-manager/src/main/resources/mapper/CategoryBrandMapper .xml +++ b/spzx-manager/src/main/resources/mapper/CategoryBrandMapper .xml @@ -6,6 +6,12 @@ id,brand_id,category_id,create_time,update_time,is_deleted + + + insert into category_brand (id, brand_id, category_id, create_time, update_time, is_deleted) + values (#{id}, #{brandId}, #{categoryId}, now(), now(), 0); + +