基于springboot的论坛系统

基于springboot的论坛系统


基本的接口有:
发帖、查看贴子【帖子的评论数】、发表评论、根据帖子ID查询评论信息、查询置顶的帖子、查询最新的帖子、查询热门帖子、查询我的帖子、查询我评论的帖子、根据帖子ID删除帖子、根据评论ID删除评论、
查询所有对我帖子的评论、查询所有对我帖子的评论数、查询对我评论的回复、 查询对我评论的回复数

创建三张表:帖子表:post 评论表:comment 贴子的热度表:post_hot
评论表:
在这里插入图片描述
post表:
在这里插入图片描述
帖子热度表:
在这里插入图片描述

  @ApiOperation("根据帖子ID查询评论信息")
    @GetMapping("/detailComment/{postId}")
    public ApiResult datailComment(@ApiParam(value = "帖子id",required = true)@PathVariable("postId")Integer postId,
                                   @ApiParam(value = "页码",required = true)@RequestParam("pageNum") Integer pageNum,
                                   @ApiParam(value = "页码",required = true)@RequestParam("pageSize")Integer pageSize){
        return commentService.datailComment(postId,pageNum,pageSize);
    }
 @Override
    public ApiResult datailComment(Integer postId,Integer pageNum,Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        //查询一级评论
        QueryWrapper<Comment> qw = new QueryWrapper<>();
        qw.eq("post_id",postId).eq("parent_id",0).eq("is_delete",0).orderByDesc("comment_time");
        List<CommentVO> commentVOList = list(qw).stream().map(CommentVO::of).collect(Collectors.toList());
        //查询二级评论信息
        commentVOList.forEach(item->{
            qw.clear();
            qw.eq("parent_id",item.getId()).eq("post_id",postId)
              .eq("is_delete",0).orderByDesc("comment_time");
            item.setCommentVOList(list(qw).stream().map(CommentVO::of).collect(Collectors.toList()));
        });
        PageInfo<CommentVO> pageInfo = new PageInfo<>(commentVOList);
        return ApiResult.success(pageInfo);
    }
@Data
@Builder
public class CommentVO {
    @ApiModelProperty("id")
    private Integer id;
    @ApiModelProperty("用户id")
    private Integer userId;
    @ApiModelProperty("帖子id")
    private Integer postId;
    @ApiModelProperty("父评论的用户id")
    private Integer parentUserId;
    @ApiModelProperty("父评论id")
    private Integer parentId;
    @ApiModelProperty("评论内容")
    private String content;
    @ApiModelProperty("评论时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date commentTime;
    @ApiModelProperty("所有的二级评论")
    private List<CommentVO> commentVOList;

    public static CommentVO of(Comment comment){
        CommentVO commentVO = CommentVO.builder().build();
        BeanUtils.copyProperties(comment,commentVO);
        return commentVO;
    }
}//注意了CommentVO不能直接new对象。

具体代码在:https://gitee.com/yzq1831914/forum-system.git

  • 6
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值