document
API test

更新品牌

POST
http://localhost:88/api/product/brand/update

API description

更新品牌信息

Request Parameters

parameter
type
description
required
brandId
long
示例:9
required
descript
string
示例:华为
required
firstLetter
string
示例:H
required
logo
string
示例:https://bitmall-oss.oss-cn-guangzhou.aliyuncs.com/2023-07-11/8a6eb10f-5d09-4508-8c04-c82301710508_huawei.png
required
name
string
示例:华为
required
showStatus
int
示例:1
required
sort
int
示例:1
required

Response Parameters

parameter
type
description
required
msg
string
示例:success
required
code
int
示例:0
required

Description or Example

# 核心代码 ```java @RequestMapping("/update") // @RequiresPermissions("product:brand:update") public R update(@Validated(UpdateGroup.class) @RequestBody BrandEntity brand){ brandService.updateSync(brand); return R.ok(); } ``` ```java CategoryBrandRelationServiceImpl @Override public void updateBrand(Long brandId, String brandName) { // 更新品牌分类关系表 CategoryBrandRelationEntity categoryBrandRelationEntity = new CategoryBrandRelationEntity(); // 创建实例 categoryBrandRelationEntity.setBrandId(brandId).setBrandName(brandName); // 创建查询条件 LambdaUpdateWrapper<CategoryBrandRelationEntity> updateWrapper = new LambdaUpdateWrapper<>(); updateWrapper.eq(CategoryBrandRelationEntity::getBrandId, brandId); // 更新 this.baseMapper.update(categoryBrandRelationEntity, updateWrapper); } ``` ```java BrandServiceImpl @Override @Transactional public void updateSync(BrandEntity brand) { // 更新当前表的信息 this.baseMapper.updateById(brand); Long brandId = brand.getBrandId(); String brandName = brand.getName(); // 判断是否需要同步更新 if (StringUtils.isNotBlank(brandName)) { categoryBrandRelationService.updateBrand(brandId, brandName); } // TODO: 其他的同步更新 } ``` # 拓展知识 ## 为什么需要同步更新 > 如果不同步更新, 冗余字段的值与本表的值不一致, 数据不一致问题 ## 为什么添加事务 > 这里涉及了两个表的数据更新, 假设当我们更新一个表, 另一个表更新失败, 会导致数据不一致的问题, 因此需要添加事务保证ACID特性