评论回复功能的数据库设计可以分开设计成两张表,评论表和回复表,也可以将其设计为一张表,我采用的是一张表
评论回复表的相关字段(我做的是商品goods下的评论回复)

字段解释:

gc_id:评论回复表id
gc_uid:评论用户id(外键)
gc_content:评论内容
gc_time:评论时间
gc_gid:评论的商品id(外键)
gc_status:评论状态(1未删除0已删除)
gc_parentid:父级评论的id,如果不是对评论的回复,那么该值为null

我在评论回复表中添加了几条数据

接下来是代码部分了
采用的是 springboot+mybatis
1.GoodsComment 的pojo类

public class GoodsComment {private Integer gcId;private Integer gcGid;private Integer gcUid;private Date gcTime;private String gcContent;private Integer gcStatus;private Integer gcParentid;private Goods goods;private Users users;private List<GoodsComment> child;// 略去了getter和setter方法
}

2.GoodsCommentMapper.java

public interface GoodsCommentMapper {// 根据商品id查询该商品下的所有评论List<GoodsComment> findByGoodId(@Param("gId") Integer gId);
}

3.GoodsCommentService.java

public interface GoodsCommentService {// 根据商品id查询该商品下的所有评论List<GoodsComment> findByGoodId(Integer gId);
}

4.GoodsCommentServiceImpl.java

@Service
public class GoodsCommentServiceImpl implements GoodsCommentService {@Resourceprivate GoodsCommentMapper goodsCommentMapper;@Overridepublic List<GoodsComment> findByGoodId(Integer gId) {return goodsCommentMapper.findByGoodId(gId);}
}

5.GoodsCommentMapper.xml

<select id="findByGoodId" resultMap="BaseResultMap">SELECT a.*,b.*FROM goods_comment AS a,users AS bWHERE a.gc_gId=#{gId}AND a.gc_status=b.u_status=1AND a.gc_uid=b.u_id
</select>

6.CoodsCommentController.java

@RestController
@RequestMapping("/goodsComment")
public class GoodsCommentController {@Autowiredprivate GoodsCommentService commentService;/*** 根据商品id查询该商品下的所有评论* @param gId* @return*/@GetMapping("/findByGoodId/{gId}")public List<GoodsComment> findByGoodId(@PathVariable("gId") Integer gId) {List<GoodsComment> allComments = commentService.findByGoodId(gId);if (allComments == null || allComments.size() == 0) {return new ArrayList<>();}List<GoodsComment> comments = new ArrayList<>();List<GoodsComment> parents = new ArrayList<>();for (GoodsComment comment : allComments) {if (comment.getGcParentid()==null) {comments.add(comment);parents.add(comment);} else {boolean foundParent=false;for (GoodsComment parent : parents) {if (comment.getGcParentid() == parent.getGcId()) {if (parent.getChild() == null) {parent.setChild(new ArrayList<>());}parent.getChild().add(comment);parents.add(comment);foundParent=true;//如果对list迭代过程中同时修改list,会报java.util.ConcurrentModificationException// 的异常,所以我们需要break,当然break也可以提高算法效率break;}}if (!foundParent) {throw new RuntimeException("can not find the parent comment");}}}return comments;}
}

7.获取到的数据部分

[{"gcId": 1,"gcGid": 1,"gcUid": 11,"gcTime": "2020-03-13T14:29:52.000+0000","gcContent": "我是评论商品的","gcStatus": 1,"gcParentid": null,"goods": null,"users": {"uId": 11,"uName": "小陈","uAvatar": "http://imgs/FjrnXL4DP6Ib8xmZmXQU5vy5GWvq"},"child": [{"gcId": 3,"gcGid": 1,"gcUid": 6,"gcTime": "2020-03-15T16:31:49.000+0000","gcContent": "我是回复","gcStatus": 1,"gcParentid": 1,"goods": null,"users": {"uId": 6,"uName": "小贰","uAvatar": "http://imgs/Fi-WU4zsZ-1OTVfPg5OXyIao13SP"},"child": [{"gcId": 4,"gcGid": 1,"gcUid": 10,"gcTime": "2020-03-15T16:48:15.000+0000","gcContent": "我是回复的回复","gcStatus": 1,"gcParentid": 3,"goods": null,"users": {"uId": 10,"uName": "小贰","uAvatar": "http://imgs/Fi-WU4zsZ-1OTVfPg5OXyIao13SP"},"child": [{"gcId": 5,"gcGid": 1,"gcUid": 9,"gcTime": "2020-03-15T20:26:09.000+0000","gcContent": "我看一下新增评论","gcStatus": 1,"gcParentid": 4,"goods": null,"users": {"uId": 9,"uName": "小贰","uAvatar": "http://imgs/Fi-WU4zsZ-1OTVfPg5OXyIao13SP"},"child": null}]}]}]},{"gcId": 2,"gcGid": 1,"gcUid": 8,"gcTime": "2020-03-14T14:30:12.000+0000","gcContent": "我也是评论这个商品的","gcStatus": 1,"gcParentid": null,"goods": null,"users": {"uId": 8,"uName": "小贰","uAvatar": "http://imgs/Fi-WU4zsZ-1OTVfPg5OXyIao13SP"},"child": null}]

评论的样式

评论回复功能的设计与实现相关推荐

  1. java评论回复功能例子_Java实现评论回复功能的完整步骤

    前言 使用递归循环开发评论回复功能,适用于大部分的简单单体应用 评论功能或许是大多数的单体应用之中会用到的功能,我们会在自己所开发的项目之中进行集成该功能 大多数时候我们会将评论功能划分成以下几种: ...

  2. Java单表实现评论回复功能

    Java单表实现评论回复功能 1.简介 2.功能实现图 3.数据库设计 4.实体类 5.实现思路 6.功能实现 6.1 Sql入手 6.2 业务实现 7.前端实现 8.最终成果 1.简介 最近在写毕业 ...

  3. 实现微信公众号评论回复功能

    最近做一个项目,实现类似微信公众号评论回复功能,如图所示: 大概分以下几个组件: 表情包组件: <template><div class="showEmjio" ...

  4. thinkphp5实现评论回复功能

    由于之前写评论回复都是使用第三方插件:畅言   所以也就没什么动手,现在证号在开发一个小的项目,所以就自己动手写评论回复,没写过还真不知道评论回复功能听着简单,但仔细研究起来却无法自拔,由于用户量少, ...

  5. Android开发之评论回复功能

    Android开发之评论回复功能 一:效果图 二:具体代码 1.首先是布局文件(activity_main) 2.第二个布局文件(comment_item) 3.第三个布局文件(reply_item) ...

  6. mysql 评论回复表设计_数据库设计——评论回复功能

    1.概述 评论功能已经成为APP和网站开发中的必备功能.本文主要介绍评论功能的数据库设计. 评论功能最主要的是发表评论和回复评论(删除功能在后台).评论功能的拓展功能体现有以下几方面: (1)单篇文章 ...

  7. 使用SpringBoot实现无限级评论回复功能

    评论功能已经成为APP和网站开发中的必备功能.本文采用springboot+mybatis-plus框架,通过代码主要介绍评论功能的数据库设计和接口数据返回.我们返回的格式可以分三种方案,第一种方案是 ...

  8. 评论回复功能 asp.net_微信重大更新!公众号推送时间线打乱+7大新功能上线!怎么玩?...

    作者 |韩俊杰来源 |馒头商学院「ID:mantousxy」自从微信年初举办公开课后,每个月都没闲着,各种新功能.小改版层出不穷.就在最近,微信又接连推出几项新功能,动作让人"眼花缭乱&qu ...

  9. vue3评论回复功能

    运用的是vue3+ts,文本框和小图标使用的是ant-design-vue框架 简单的实现了页面布局,点击回复等小功能(删除数据和回复添加到数组中目前没有写,因为项目要求后面需要对接后端接口,所以就懒 ...

最新文章

  1. Strategy模式
  2. 面向对象设计模式纵横谈:Singelton单件模式(笔记记录)
  3. java steam 排序_java8 stream自定义分组求和并排序的实现
  4. 开始新的BLOG了!!
  5. SOCKET编程中,select()函数的作用
  6. CentOS 7 上 Docker 安装
  7. 509. 斐波那契数(JavaScript)
  8. gpu 加速矩阵 深度学习_GPU如何加速深度学习
  9. 网页设计html5实训心得,网页设计实习心得
  10. 数据库——数据库练习题
  11. js 大地坐标转经纬度
  12. 性能高、上手快,实体类转换工具 MapStruct 到底有多强大!
  13. 汇丰银行的华尔街恐怖故事
  14. 关于sammy的初理解
  15. android中读取svg文件,Android如何加载SVG格式的矢量图
  16. idea 设置编辑器 table 全部显示
  17. 一 Ebuy首页展示之导航栏
  18. python爬虫系列--lxml(etree/parse/xpath)的使用
  19. 2021年六级翻译:海南岛
  20. 分享一个查看css版本兼容性的网站: https://caniuse.com/

热门文章

  1. 计算机中的字节换算:【KB,MB,GB,TB,PB,EB,ZB,YB】
  2. ABAP-HTTP发送JSON
  3. 忙里偷闲附上打油诗一首
  4. Pytorch/Python计算交并比IOU(IU)代码(批量算IOU)
  5. 数据库双机热备实战总结
  6. python print影响速度_为什么打印到标准输出这么慢?可以加快速度吗?
  7. Laya3D 抗锯齿问题
  8. SpringBoot使用通配符加载配置文件
  9. 响应CMFCToolBarComboBoxButton的VK_RETURN事件
  10. iOS开发中内置浏览器