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

本文介绍了如何使用Spring Boot创建产品评论服务接口,并通过ProductCommentsServiceImpl实现具体查询操作。Controller层展示了如何调用这些服务获取商品评论信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、业务层实现
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);
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值