AttrController添加如下接口:
@PostMapping("/update/{spuId}")
public R updateSpuAttr(@PathVariable("spuId") Long spuId,
@RequestBody List<ProductAttrValueEntity> entities) {
productAttrValueService.updateSpuAttr(spuId, entities);
return R.ok();
}
ProductAttrValueService添加如下方法:
/**
* 更新规格参数
*
* @param spuId
* @param entities
*/
void updateSpuAttr(Long spuId, List<ProductAttrValueEntity> entities);
ProductAttrValueServiceImpl添加以上方法的实现,如下:
@Transactional
@Override
public void updateSpuAttr(Long spuId, List<ProductAttrValueEntity> entities) {
//全增全删
this.baseMapper.delete(new QueryWrapper<ProductAttrValueEntity>().eq("spu_id", spuId));
List<ProductAttrValueEntity> collect = entities.stream().map(item -> {
item.setSpuId(spuId);
return item;
}).collect(Collectors.toList());
this.saveBatch(collect);
}
测试效果:
原来是快速展示的选项,如下:
去掉快速选项,确认修改,如下:
重新进去看效果,如下:
可以发现快速展示属性修改成功了。