基于springboot的论坛系统

这是一个基于SpringBoot的论坛系统实现,包括发帖、查看帖子评论数、发表评论等核心功能。通过创建三张表——帖子表、评论表和帖子热度表,实现了评论的一级和二级查询。代码中详细展示了如何根据帖子ID查询评论信息,包括一级评论和二级评论的递归获取。此外,还提供了删除帖子和评论的接口。

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

基于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

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值