本文最后更新于 2026年1月14日 下午
评论点赞接口的实现
评论点赞接口的需求
根据评论id点赞评论
不能重复点赞(前端防止)
所有类型评论不用登录就可以点赞
代码实现
其实这个接口比较简单
新增评论点赞接口(Put请求格式)
1 2 3 4 5 6 7 8 9 10
|
@PutMapping("/like/{commentId}") public ResponseResult likeComment(@PathVariable("commentId") Long commentId) { return commentService.likeComment(commentId); }
|
在AppHttpCodeEnum类中新建一个关于评论不存在的枚举
实现服务
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| @Override public ResponseResult likeComment(Long commentId) { Comment comment = getById(commentId); if (comment == null || !SystemConstants.COMMENT_STATUS_NORMAL.equals(comment.getStatus())) { return ResponseResult.errorResult(AppHttpCodeEnum.COMMENT_NOT_EXIST); } comment.setLikeCount(comment.getLikeCount() + 1); updateById(comment); return ResponseResult.okResult(); }
|
PS:该系列只做为作者学习开发项目做的笔记用
不一定符合读者来学习,仅供参考
预告
后续会记录博客的开发过程
每次学习会做一份笔记来进行发表
“一花一世界,一叶一菩提”
版权所有 © 2025 云梦泽
欢迎访问我的个人网站:https://hgt12.github.io/