需求:
用户可以评论,也可以回复评论,其他用户还可以评论、回复评论。
评论表实体(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

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

被折叠的 条评论
为什么被折叠?



