mirror of https://github.com/halo-dev/halo
👽 代码优化
parent
c3deec86a7
commit
67418fd0cf
|
@ -46,7 +46,7 @@ public interface CommentRepository extends JpaRepository<Comment, Long> {
|
||||||
Page<Comment> findCommentsByPost(Post post, Pageable pageable);
|
Page<Comment> findCommentsByPost(Post post, Pageable pageable);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据文章和评论状态查询评论
|
* 根据文章和评论状态查询评论 分页
|
||||||
*
|
*
|
||||||
* @param post post
|
* @param post post
|
||||||
* @param pageable pageable
|
* @param pageable pageable
|
||||||
|
@ -55,6 +55,15 @@ public interface CommentRepository extends JpaRepository<Comment, Long> {
|
||||||
*/
|
*/
|
||||||
Page<Comment> findCommentsByPostAndCommentStatus(Post post, Pageable pageable, Integer status);
|
Page<Comment> findCommentsByPostAndCommentStatus(Post post, Pageable pageable, Integer status);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据文章和评论状态查询评论 不分页
|
||||||
|
*
|
||||||
|
* @param post post
|
||||||
|
* @param status status
|
||||||
|
* @return List
|
||||||
|
*/
|
||||||
|
List<Comment> findCommentsByPostAndCommentStatus(Post post, Integer status);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询最新的前五条评论
|
* 查询最新的前五条评论
|
||||||
*
|
*
|
||||||
|
|
|
@ -80,7 +80,7 @@ public interface CommentService {
|
||||||
Page<Comment> findCommentsByPost(Post post, Pageable pageable);
|
Page<Comment> findCommentsByPost(Post post, Pageable pageable);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据文章和评论状态查询评论
|
* 根据文章和评论状态查询评论 分页
|
||||||
*
|
*
|
||||||
* @param post post
|
* @param post post
|
||||||
* @param pageable pageable
|
* @param pageable pageable
|
||||||
|
@ -89,6 +89,15 @@ public interface CommentService {
|
||||||
*/
|
*/
|
||||||
Page<Comment> findCommentsByPostAndCommentStatus(Post post, Pageable pageable, Integer status);
|
Page<Comment> findCommentsByPostAndCommentStatus(Post post, Pageable pageable, Integer status);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据文章和评论状态查询评论 不分页
|
||||||
|
*
|
||||||
|
* @param post post
|
||||||
|
* @param status status
|
||||||
|
* @return List
|
||||||
|
*/
|
||||||
|
List<Comment> findCommentsByPostAndCommentStatus(Post post, Integer status);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询最新的前五条评论
|
* 查询最新的前五条评论
|
||||||
*
|
*
|
||||||
|
|
|
@ -137,6 +137,18 @@ public class CommentServiceImpl implements CommentService {
|
||||||
return commentRepository.findCommentsByPostAndCommentStatus(post, pageable, status);
|
return commentRepository.findCommentsByPostAndCommentStatus(post, pageable, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据文章和评论状态查询评论 不分页
|
||||||
|
*
|
||||||
|
* @param post post
|
||||||
|
* @param status status
|
||||||
|
* @return List
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<Comment> findCommentsByPostAndCommentStatus(Post post, Integer status) {
|
||||||
|
return commentRepository.findCommentsByPostAndCommentStatus(post, status);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询最新的前五条评论
|
* 查询最新的前五条评论
|
||||||
*
|
*
|
||||||
|
|
|
@ -118,12 +118,10 @@ public class FrontArchiveController extends BaseController {
|
||||||
if (null != afterPosts && afterPosts.size() > 0) {
|
if (null != afterPosts && afterPosts.size() > 0) {
|
||||||
model.addAttribute("afterPost", afterPosts.get(afterPosts.size() - 1));
|
model.addAttribute("afterPost", afterPosts.get(afterPosts.size() - 1));
|
||||||
}
|
}
|
||||||
Sort sort = new Sort(Sort.Direction.DESC, "commentDate");
|
List<Comment> comments = commentService.findCommentsByPostAndCommentStatus(post, CommentStatus.PUBLISHED.getCode());
|
||||||
Pageable pageable = PageRequest.of(0, 999, sort);
|
|
||||||
Page<Comment> comments = commentService.findCommentsByPostAndCommentStatus(post, pageable, CommentStatus.PUBLISHED.getCode());
|
|
||||||
model.addAttribute("post", post);
|
model.addAttribute("post", post);
|
||||||
model.addAttribute("comments", CommentUtil.getComments(comments.getContent()));
|
model.addAttribute("comments", CommentUtil.getComments(comments));
|
||||||
model.addAttribute("commentsCount", comments.getTotalElements());
|
model.addAttribute("commentsCount", comments.size());
|
||||||
postService.updatePostView(post);
|
postService.updatePostView(post);
|
||||||
return this.render("post");
|
return this.render("post");
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,10 +11,6 @@ import cc.ryanc.halo.service.PostService;
|
||||||
import cc.ryanc.halo.utils.CommentUtil;
|
import cc.ryanc.halo.utils.CommentUtil;
|
||||||
import cc.ryanc.halo.web.controller.core.BaseController;
|
import cc.ryanc.halo.web.controller.core.BaseController;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.Page;
|
|
||||||
import org.springframework.data.domain.PageRequest;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
|
||||||
import org.springframework.data.domain.Sort;
|
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
@ -70,16 +66,13 @@ public class FrontPageController extends BaseController {
|
||||||
@GetMapping(value = "/p/{postUrl}")
|
@GetMapping(value = "/p/{postUrl}")
|
||||||
public String getPage(@PathVariable(value = "postUrl") String postUrl, Model model) {
|
public String getPage(@PathVariable(value = "postUrl") String postUrl, Model model) {
|
||||||
Post post = postService.findByPostUrl(postUrl, PostType.POST_TYPE_PAGE.getDesc());
|
Post post = postService.findByPostUrl(postUrl, PostType.POST_TYPE_PAGE.getDesc());
|
||||||
|
if (null == post) {
|
||||||
Sort sort = new Sort(Sort.Direction.DESC,"commentDate");
|
|
||||||
Pageable pageable = PageRequest.of(0,999,sort);
|
|
||||||
Page<Comment> comments = commentService.findCommentsByPostAndCommentStatus(post,pageable,CommentStatus.PUBLISHED.getCode());
|
|
||||||
if(null==post){
|
|
||||||
return this.renderNotFound();
|
return this.renderNotFound();
|
||||||
}
|
}
|
||||||
|
List<Comment> comments = commentService.findCommentsByPostAndCommentStatus(post, CommentStatus.PUBLISHED.getCode());
|
||||||
model.addAttribute("post", post);
|
model.addAttribute("post", post);
|
||||||
model.addAttribute("comments", CommentUtil.getComments(comments.getContent()));
|
model.addAttribute("comments", CommentUtil.getComments(comments));
|
||||||
model.addAttribute("commentsCount", comments.getTotalElements());
|
model.addAttribute("commentsCount", comments.size());
|
||||||
postService.updatePostView(post);
|
postService.updatePostView(post);
|
||||||
return this.render("page");
|
return this.render("page");
|
||||||
}
|
}
|
||||||
|
|
|
@ -258,7 +258,7 @@
|
||||||
<#macro childComments comments>
|
<#macro childComments comments>
|
||||||
<ul class="native-list" style="margin-left: 30px; border-left: 1px solid #f1f1f1">
|
<ul class="native-list" style="margin-left: 30px; border-left: 1px solid #f1f1f1">
|
||||||
<#if comments?? && comments?size gt 0>
|
<#if comments?? && comments?size gt 0>
|
||||||
<#list comments as comment>
|
<#list comments?sort_by("commentDate") as comment>
|
||||||
<li class="native-list-one" id="comment-id-${comment.commentId?c}" style="margin-left: 5px;">
|
<li class="native-list-one" id="comment-id-${comment.commentId?c}" style="margin-left: 5px;">
|
||||||
<img class="native-list-one-img" style="width: 2rem;height: 2rem;" src="//gravatar.loli.net/avatar/${comment.commentAuthorAvatarMd5?if_exists}?s=256&d=${options.native_comment_avatar?default('mm')}">
|
<img class="native-list-one-img" style="width: 2rem;height: 2rem;" src="//gravatar.loli.net/avatar/${comment.commentAuthorAvatarMd5?if_exists}?s=256&d=${options.native_comment_avatar?default('mm')}">
|
||||||
<section>
|
<section>
|
||||||
|
@ -287,7 +287,7 @@
|
||||||
</#macro>
|
</#macro>
|
||||||
<ul class="native-list">
|
<ul class="native-list">
|
||||||
<#if comments?? && comments?size gt 0>
|
<#if comments?? && comments?size gt 0>
|
||||||
<#list comments as comment>
|
<#list comments?sort_by("commentDate")?reverse as comment>
|
||||||
<li class="native-list-one" id="comment-id-${comment.commentId?c}">
|
<li class="native-list-one" id="comment-id-${comment.commentId?c}">
|
||||||
<img class="native-list-one-img" src="//gravatar.loli.net/avatar/${comment.commentAuthorAvatarMd5?if_exists}?s=256&d=${options.native_comment_avatar?default('mm')}">
|
<img class="native-list-one-img" src="//gravatar.loli.net/avatar/${comment.commentAuthorAvatarMd5?if_exists}?s=256&d=${options.native_comment_avatar?default('mm')}">
|
||||||
<section>
|
<section>
|
||||||
|
|
|
@ -44,7 +44,7 @@
|
||||||
</h3>
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="post-content">
|
<div class="post-content">
|
||||||
${post.postContent}
|
${post.postContent?if_exists}
|
||||||
</div>
|
</div>
|
||||||
<div class="post-footer">
|
<div class="post-footer">
|
||||||
<div class="meta">
|
<div class="meta">
|
||||||
|
|
Loading…
Reference in New Issue