为了账号安全,请及时绑定邮箱和手机立即绑定

评论树,回复回复即可显示

评论树,回复回复即可显示

忽然笑 2023-11-10 15:55:38
我需要实现评论树,但无法获得回复工作的回复。Comment.java...    @Id    @GeneratedValue(strategy = GenerationType.IDENTITY)    private Long id;    private String content;    @ManyToOne    private Post post;    @ManyToOne    private Comment parent;    @OneToMany(mappedBy = "parent")    private List<Comment> children = new ArrayList<Comment>();...PostController.javamodel.addAttribute("comments", commentRepository.findAllCommentsByPostIdAndParentIsNull(id));帖子.html<th:block th:each="comment : ${comments}"><p th:text="${comment.content}">comment</p><th:block th:each="child : ${comment.children}"><div class="child">  <p th:text="${child.content}">comment</p></div></th:block></th:block>评论数据库ID | CONTENT | PARENT_ID | POST_ID1    text1         null        12    text2          1          13    text3          2          14    text4         null        1我想要的输出text1  text2    text3text4我得到的输出text1 text2text4基本上回复的回复都不会显示。我该如何获得我想要的输出?
查看完整描述

1 回答

?
撒科打诨

TA贡献1934条经验 获得超2个赞

尝试以下方法


<th:block th:each="comment : ${comments}">

  <p th:text="${comment.content}">comment</p>

  <div th:fragment="f_call(comment)" 

      th:unless="${#lists.isEmpty(comment.children)}" >

      <div th:each="child : ${comment.children}" th:inline="text">

          [[${child.content}]]

          <div th:replace="this::f_call(${child})"></div>

      </div>

  </div>

</th:block>


查看完整回答
反对 回复 2023-11-10
  • 1 回答
  • 0 关注
  • 50 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信