@Override
public Result<Product> findById(Integer id) {
Product p = productRepository.findOne(id);
if(p==null){
return new Result<>(412);
}
return new Result<>(200,"OK",p);
}
2:findById(id)
@Override
public Result<Comments> findById(Integer id) {
Optional<Comments> optional = commentsRepository.findById(id);
if (optional == null || !optional.isPresent()) {
return new Result(415, "信息不存在");
}
Comments comments = optional.get();
if (comments == null) {
return new Result(415, "信息不存在");
}
return new Result(200, "OK", comments);
}
@Override
public Result<Spu> findById(Integer id) {
Optional<Spu> optional = spuRepository.findById(id);
return optional.map(spu -> new Result<>(BaseUtils.TWO_HUNDRED, "OK", spu)).orElseGet(() -> new Result<>(BaseUtils.FOUR_FOURTEEN));
}