本文最后更新于 2026年5月3日 上午
回复评论接口的实现
回复评论接口的需求
先获取登录者信息
如果是管理员则允许回复,如果不是则不允许回复
管理员评论默认审核通过
代码实现
下面只展示 AdminCommentServiceImpl 里的代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| @Override public ResponseResult replyComment(ReplyCommentDto replyCommentDto) { LoginUser loginUser = SecurityUtils.getLoginUser(); if (loginUser == null) { return ResponseResult.errorResult(AppHttpCodeEnum.NEED_LOGIN, "用户未登录"); } if (!SecurityUtils.isAdmin()) { return ResponseResult.errorResult(AppHttpCodeEnum.NO_OPERATOR_AUTH, "只有系统管理员才能回复评论"); } SysUser currentUser = loginUser.getSysUser(); Comment comment = new Comment(); BeanUtils.copyProperties(replyCommentDto, comment); comment.setUserId(currentUser.getId()); comment.setNickname(currentUser.getNickname()); comment.setEmail(currentUser.getEmail()); comment.setAvatar(currentUser.getAvatar()); comment.setStatus(SystemConstants.COMMENT_STATUS_NORMAL); comment.setLikeCount(SystemConstants.DEFAULT_COMMENT_LIKES); int result = commentMapper.insert(comment); if (result > 0) { return ResponseResult.okResult("回复成功"); } else { return ResponseResult.errorResult(AppHttpCodeEnum.SYSTEM_ERROR, "回复失败"); } }
|
测试接口
PS:该系列只做为作者学习开发项目做的笔记用
不一定符合读者来学习,仅供参考
预告
后续会记录博客的开发过程
每次学习会做一份笔记来进行发表
“一花一世界,一叶一菩提”
版权所有 © 2026 云梦泽
欢迎访问我的个人网站:https://hgt12.github.io/