千峰商城-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 @   临易  阅读(49)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
点击右上角即可分享
微信分享提示