Skip to content

Commit 809f664

Browse files
committed
🩹 修改评论的显示顺序
1 parent 7e1d37a commit 809f664

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

blog-api/src/main/java/top/naccl/service/impl/CommentServiceImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import top.naccl.service.CommentService;
1111

1212
import java.util.ArrayList;
13+
import java.util.Comparator;
1314
import java.util.List;
1415

1516
/**
@@ -39,6 +40,11 @@ public List<PageComment> getPageCommentList(Integer page, Long blogId, Long pare
3940
for (PageComment c : comments) {
4041
List<PageComment> tmpComments = new ArrayList<>();
4142
getReplyComments(tmpComments, c.getReplyComments());
43+
//对于两列评论来说,按时间顺序排列应该比树形更合理些
44+
//排序一下
45+
Comparator<PageComment> comparator = (c1, c2) -> c1.getCreateTime().compareTo(c2.getCreateTime());
46+
tmpComments.sort(comparator);
47+
4248
c.setReplyComments(tmpComments);
4349
}
4450
return comments;

0 commit comments

Comments
 (0)