亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

評論樹,回復回復即可顯示

評論樹,回復回復即可顯示

忽然笑 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 關注
  • 152 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號