JAVA设计评论列表数据格式

本文介绍了一种基于树形结构的文章评论系统实现方案。通过递归查询子评论并组装成树形结构,实现了多级评论及回复功能。具体包括评论表设计、前后端交互流程、SQL查询语句及递归算法。

需求:

用户可以评论,也可以回复评论,其他用户还可以评论、回复评论。

评论表实体(ArticleComment)

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
 * 评论表
 *
 * @author create by xiegege
 * @date 2021/6/17 16:00
 * 表中的levelFlag为评论等级,1表示一级,主要是文章的直接评论, 2表示二级,主要是主题评论的回复
 **/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("sys_article_comment")
@ApiModel(value = "ArticleComment对象", description = "评论表")
public class ArticleComment {
   
   

    @ApiModelProperty(value = "评论主键")
    @TableId("id")
    private Long id;

    @ApiModelProperty(value = "评论的文章Id")
    @TableField("article_id")
    private Long articleId;

    @ApiModelProperty(value = "父级评论Id")
    @TableField("parent_id")
    private Long parentId;

    @ApiModelProperty(value = "评论内容")
    @TableField("comment_content")
    private String commentContent;

    @ApiModelProperty(value = "评论等级")
    @TableField("level_flag")
    private Integer levelFlag;

    @ApiModelProperty(value = "点赞数")
    @TableField("upvote_count")
    private Integer upvoteCount;

    @ApiModelProperty(value = "是否置顶评论(0否,1是)")
    @TableField("whether_top")
    private Integer whetherTop;

    @ApiModelProperty(value = "用户Id")
    @TableField("user_id")
    private Long userId;

    @ApiModelProperty(value = "创建时间")
    @TableField("create_time")
    private String createTime;
}

建表sql语句

CREATE TABLE `sys_article_comment` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '评论主键',
  `article_id` bigint(20) NOT NULL COMMENT '评论的文章Id',
  `parent_id` bigint(20) NOT NULL COMMENT '父级评论Id',
  `comment_content` varchar(255) NOT NULL COMMENT '评论内容',
  `level_flag` int(10) NOT NULL COMMENT '评论等级:1主评论,2子评论',
  `upvote_count` int(10) NOT NULL DEFAULT '0' COMMENT '评论点赞数量',
  `whether_top` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否置顶评论(0否,1是)',
  `user_id` bigint(20) NOT NULL COMMENT '用户id',
  `create_time` datetime NOT NULL COMMENT '创建时间',
  PRIMARY KEY (`id`),
  KEY 
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

谢咯咯剥壳

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值