重點不是控制層和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);
}
}