作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要实现评论树,但无法获得回复工作的回复。
评论.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.java
model.addAttribute("comments", commentRepository.findAllCommentsByPostIdAndParentIsNull(id));
post.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_ID
1 text1 null 1
2 text2 1 1
3 text3 2 1
4 text4 null 1
我想要的输出
text1
text2
text3
text4
我得到的输出
text1
text2
text4
基本上不会显示对回复的回复。
我如何获得我想要的输出?
最佳答案
尝试以下操作
<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>
关于java - 评论树,回复回复即可显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58438561/
这实际上是我问的问题的一部分here ,该问题没有得到答复,最终被标记为重复。 问题:我只需使用 @Autowired 注释即可使用 JavaMailSender。我没有通过任何配置类公开它。 @Co
我是一名优秀的程序员,十分优秀!