mall-tiny-06 EsProductServiceImpl create方法错误

#127 · closed · 0 comments

View on GitHub ↗

OrigamiWang

**源代码中的create方法,入参为id,根本无法添加新的商品** ``` // 修改后的方法(仅供参考) @Override public CommonResult<EsProduct> create(EsProduct esProduct) { if (esProduct != null) { long id = esProduct.getId(); Iterable<EsProduct> all = productRepository.findAll(); Iterator<EsProduct> iterator = all.iterator(); while (iterator.hasNext()) { Long id1 = iterator.next().getId(); if (Objects.equal(id, id1)) { LOGGER.warn("此id: {}已经被创建", id); return CommonResult.failed(); } } productRepository.save(esProduct); LOGGER.info("创建商品成功,id:{}", id); return CommonResult.success(esProduct); } return CommonResult.failed(); } ```

Comments