Description or Example
# BUG修复
## 404页面了怎么办?

# 核心代码
```java
@RequestMapping("/update/{spuId}")
public R updateBaseAttr(@PathVariable("spuId") Long spuId,
@RequestBody List<ProductAttrValueEntity> productAttrValueEntities) {
productAttrValueService.updateBaseAttrBySpuId(spuId, productAttrValueEntities);
return R.ok();
}
```
```java
@Override
@Transactional
public void updateBaseAttrBySpuId(Long spuId, List<ProductAttrValueEntity> productAttrValueEntities) {
// 根据spuId将原来的全部删掉
LambdaUpdateWrapper<ProductAttrValueEntity> wrapper = new LambdaUpdateWrapper<>();
wrapper.eq(ProductAttrValueEntity::getSpuId, spuId);
this.baseMapper.delete(wrapper);
// 必须设置规格参数, 否则更新无效
if (productAttrValueEntities != null && !productAttrValueEntities.isEmpty()) {
List<ProductAttrValueEntity> entities = productAttrValueEntities.stream().map(productAttrValueEntity
-> productAttrValueEntity.setSpuId(spuId))
.collect(Collectors.toList());
this.saveBatch(entities);
}else {
throw new RuntimeException("必须设置规格参数");
}
}
```
# 扩展知识
## 更新数据的策略是什么?
> 首先明确的是, 一个SPU下可能会有多个规格参数, 如果要对这些规格参数进行修改, 如果在原来的基础上修改, 会非常的麻烦, 所以, 采取了一种更为便捷的方式
> 即, 将原来所有的规格参数都删除了, 以最终跟新的规格参数为准添加