千峰商城-springboot项目搭建-68-商品评论-接口实现

一、业务层实现
 
1.创建接口定义方法:
productCommentsService 
public interface productCommentsService {
    public ResultVO listCommentsByProductId(String productId);
}

 

2.创建实现类实现查询操作:

productCommentsServiceImpl :
@Service
public class productCommentsServiceImpl implements productCommentsService {
    
    @Autowired
    private ProductCommentsMapper productCommentsMapper;
    
    
    public ResultVO listCommentsByProductId(String productId) {
        List<ProductCommentsVO> productCommentsVOS = productCommentsMapper.selectCommontsByProductId(productId);

        ResultVO resultVO = new ResultVO(ResStatus.OK, "success", productCommentsVOS);
        
        return resultVO;
    }
}

 

 

 二、控制层实现

ProductController 
@RestController
@CrossOrigin
@RequestMapping("/product")
@Api(value = "提供商品信息相关的接口",tags = "商品管理")
public class ProductController {

    @Autowired
    private ProductService productService;
    @Autowired
    private ProductCommentsService productCommentsService;

    @ApiOperation("商品基本信息查询接口")
    @GetMapping("/detail-info/{pid}")
    public ResultVO getProductBasicInfo(@PathVariable("pid") String pid){
        return productService.getProductBasicInfo(pid);
    }

    @ApiOperation("商品参数信息查询接口")
    @GetMapping("/detail-params/{pid}")
    public ResultVO getProductParams(@PathVariable("pid") String pid){
        return productService.getProductParamsById(pid);
    }

    @ApiOperation("商品评论信息查询接口")
    @GetMapping("/detail-commonts/{pid}")
    public ResultVO getProductCommonts(@PathVariable("pid") String pid){
        return productCommentsService.listCommentsByProductId(pid);
    }
}

 

 

 

 

 

 

 

 

 

 
posted @ 2022-07-21 20:08  临易  阅读(54)  评论(0)    收藏  举报