重点不是控制层和service层,在 impl 实现层业务处理
controller层
@ApiOperation(value = "根据id批量删除商品")
@POSTMapping( "/delete/batch")
public CommonResult<Object> delete(@RequestParam("ids") List<Long> ids) {
esProductService.delete(ids);
return CommonResult.success(null);
}
service层
/**
* 批量删除商品
*/
void delete(List<Long> ids);
impl实现
@Override
public void delete(List<Long> ids) {
if (!CollectionUtils.isEmpty(ids)) {
List<EsProduct> esProductList = new ArrayList<>();
for (Long id : ids) {
EsProduct esProduct = new EsProduct();
esProduct.setId(id);
esProductList.add(esProduct);
}
productRepository.deleteAll(esProductList);
}
}