🎨 代码优化

pull/78/head
ruibaby 2019-01-05 17:16:56 +08:00
parent da923f3469
commit d63f7943b4
9 changed files with 125 additions and 56 deletions

2
docs/README-en-US.md → README-en_US.md Executable file → Normal file
View File

@ -11,7 +11,7 @@
</p> </p>
------------------------------ ------------------------------
🇨🇳[简体中文](../README.md) | 🇺🇸English 🇨🇳[简体中文](README.md) | 🇺🇸English
## Introduction ## Introduction

View File

@ -11,7 +11,7 @@
</p> </p>
------------------------------ ------------------------------
🇨🇳简体中文 | 🇺🇸[English](./docs/README-en-US.md) 🇨🇳简体中文 | 🇺🇸[English](README-en_US.md)
## 简介 ## 简介

View File

@ -60,7 +60,7 @@ public class StartedListener implements ApplicationListener<ApplicationStartedEv
if (StrUtil.isNotEmpty(themeValue) && !StrUtil.equals(themeValue, null)) { if (StrUtil.isNotEmpty(themeValue) && !StrUtil.equals(themeValue, null)) {
BaseController.THEME = themeValue; BaseController.THEME = themeValue;
} else { } else {
//以防万一 //如果没有设置主题,则默认
BaseController.THEME = "anatole"; BaseController.THEME = "anatole";
} }
configuration.setSharedVariable("themeName", BaseController.THEME); configuration.setSharedVariable("themeName", BaseController.THEME);

View File

@ -34,6 +34,7 @@ public interface PostRepository extends JpaRepository<Post, Long> {
* *
* *
* @param postType post or page * @param postType post or page
*
* @return List * @return List
*/ */
List<Post> findPostsByPostType(String postType); List<Post> findPostsByPostType(String postType);
@ -43,6 +44,7 @@ public interface PostRepository extends JpaRepository<Post, Long> {
* *
* @param postType post or page * @param postType post or page
* @param pageable * @param pageable
*
* @return Page * @return Page
*/ */
Page<Post> findPostsByPostType(String postType, Pageable pageable); Page<Post> findPostsByPostType(String postType, Pageable pageable);
@ -52,6 +54,7 @@ public interface PostRepository extends JpaRepository<Post, Long> {
* *
* @param keyWord keyword * @param keyWord keyword
* @param pageable pageable * @param pageable pageable
*
* @return List * @return List
*/ */
List<Post> findByPostTitleLike(String keyWord, Pageable pageable); List<Post> findByPostTitleLike(String keyWord, Pageable pageable);
@ -62,6 +65,7 @@ public interface PostRepository extends JpaRepository<Post, Long> {
* @param status 012 * @param status 012
* @param postType post or page * @param postType post or page
* @param pageable * @param pageable
*
* @return Page * @return Page
*/ */
Page<Post> findPostsByPostStatusAndPostType(Integer status, String postType, Pageable pageable); Page<Post> findPostsByPostStatusAndPostType(Integer status, String postType, Pageable pageable);
@ -71,6 +75,7 @@ public interface PostRepository extends JpaRepository<Post, Long> {
* *
* @param status 0,1,2 * @param status 0,1,2
* @param postType post or page * @param postType post or page
*
* @return List * @return List
*/ */
List<Post> findPostsByPostStatusAndPostType(Integer status, String postType); List<Post> findPostsByPostStatusAndPostType(Integer status, String postType);
@ -80,6 +85,7 @@ public interface PostRepository extends JpaRepository<Post, Long> {
* *
* @param postUrl * @param postUrl
* @param postType post or page * @param postType post or page
*
* @return Post * @return Post
*/ */
Post findPostByPostUrlAndPostType(String postUrl, String postType); Post findPostByPostUrlAndPostType(String postUrl, String postType);
@ -89,30 +95,30 @@ public interface PostRepository extends JpaRepository<Post, Long> {
* *
* @param postId * @param postId
* @param postType post or page * @param postType post or page
*
* @return Post * @return Post
*/ */
Post findPostByPostIdAndPostType(Long postId, String postType); Post findPostByPostIdAndPostType(Long postId, String postType);
/** /**
* *
* *
* @param postDate * @param postDate
* @param postStatus 012 *
* @param postType post or page * @return Post
* @return List
*/ */
List<Post> findByPostDateAfterAndPostStatusAndPostTypeOrderByPostDateDesc(Date postDate, Integer postStatus, String postType); @Query(value = "SELECT * FROM halo_post WHERE post_status = 0 AND post_type='post' AND post_date < :postDate ORDER BY post_date DESC LIMIT 1", nativeQuery = true)
Post queryPrePost(Date postDate);
/** /**
* *
* *
* @param postDate * @param postDate
* @param postStatus 012 *
* @param postType post or page * @return Post
* @return List
*/ */
List<Post> findByPostDateBeforeAndPostStatusAndPostTypeOrderByPostDateAsc(Date postDate, Integer postStatus, String postType); @Query(value = "SELECT * FROM halo_post WHERE post_status = 0 AND post_type='post' AND post_date > :postDate ORDER BY post_date ASC LIMIT 1", nativeQuery = true)
Post queryNextPost(Date postDate);
/** /**
* *
@ -132,32 +138,34 @@ public interface PostRepository extends JpaRepository<Post, Long> {
/** /**
* @return List
*
* @Author Aquan * @Author Aquan
* @Description * @Description
* @Date 2019.1.4 11:19 * @Date 2019.1.4 11:19
* @Param * @Param
* @return List
**/ **/
@Query(value = "SELECT *,YEAR(post_date) AS YEAR FROM halo_post WHERE post_status=0 AND post_type='post' ORDER BY post_date DESC", nativeQuery = true) @Query(value = "SELECT *,YEAR(post_date) AS YEAR FROM halo_post WHERE post_status=0 AND post_type='post' ORDER BY post_date DESC", nativeQuery = true)
List<Post> findAllPost(); List<Post> findAllPost();
/** /**
* @return Integer
*
* @Author Aquan * @Author Aquan
* @Description * @Description
* @Date 2019.1.4 15:03 * @Date 2019.1.4 15:03
* @Param * @Param
* @return Integer
**/ **/
@Query(value = "SELECT count(1) AS COUNT FROM halo_post WHERE post_status=0 AND post_type='post'", nativeQuery = true) @Query(value = "SELECT count(1) AS COUNT FROM halo_post WHERE post_status=0 AND post_type='post'", nativeQuery = true)
Integer totalAllPostCount(); Integer totalAllPostCount();
/** /**
* *
* *
* @param year year * @param year year
* @param month month * @param month month
*
* @return List * @return List
*/ */
@Query(value = "SELECT *,YEAR(post_date) AS YEAR,MONTH(post_date) AS MONTH FROM halo_post WHERE post_status=0 and post_type='post' AND YEAR(post_date)=:year AND MONTH(post_date)=:month ORDER BY post_date DESC", nativeQuery = true) @Query(value = "SELECT *,YEAR(post_date) AS YEAR,MONTH(post_date) AS MONTH FROM halo_post WHERE post_status=0 and post_type='post' AND YEAR(post_date)=:year AND MONTH(post_date)=:month ORDER BY post_date DESC", nativeQuery = true)
@ -167,6 +175,7 @@ public interface PostRepository extends JpaRepository<Post, Long> {
* *
* *
* @param year year * @param year year
*
* @return List * @return List
*/ */
@Query(value = "SELECT *,YEAR(post_date) AS YEAR FROM halo_post WHERE post_status=0 AND post_type='post' AND YEAR(post_date)=:year ORDER BY post_date DESC", nativeQuery = true) @Query(value = "SELECT *,YEAR(post_date) AS YEAR FROM halo_post WHERE post_status=0 AND post_type='post' AND YEAR(post_date)=:year ORDER BY post_date DESC", nativeQuery = true)
@ -178,6 +187,7 @@ public interface PostRepository extends JpaRepository<Post, Long> {
* @param year year * @param year year
* @param month month * @param month month
* @param pageable pageable * @param pageable pageable
*
* @return Page * @return Page
*/ */
@Query(value = "SELECT * FROM halo_post WHERE post_status=0 and post_type='post' AND YEAR(post_date)=:year AND MONTH(post_date)=:month ORDER BY post_date DESC", countQuery = "SELECT COUNT(*) FROM halo_post WHERE post_status=0 AND YEAR(post_date)=:year AND MONTH(post_date)=:month", nativeQuery = true) @Query(value = "SELECT * FROM halo_post WHERE post_status=0 and post_type='post' AND YEAR(post_date)=:year AND MONTH(post_date)=:month ORDER BY post_date DESC", countQuery = "SELECT COUNT(*) FROM halo_post WHERE post_status=0 AND YEAR(post_date)=:year AND MONTH(post_date)=:month", nativeQuery = true)
@ -189,6 +199,7 @@ public interface PostRepository extends JpaRepository<Post, Long> {
* @param category category * @param category category
* @param status status * @param status status
* @param pageable pageable * @param pageable pageable
*
* @return Page * @return Page
*/ */
Page<Post> findPostByCategoriesAndPostStatus(Category category, Integer status, Pageable pageable); Page<Post> findPostByCategoriesAndPostStatus(Category category, Integer status, Pageable pageable);
@ -199,6 +210,7 @@ public interface PostRepository extends JpaRepository<Post, Long> {
* @param tag tag * @param tag tag
* @param status status * @param status status
* @param pageable pageable * @param pageable pageable
*
* @return Page * @return Page
*/ */
Page<Post> findPostsByTagsAndPostStatus(Tag tag, Integer status, Pageable pageable); Page<Post> findPostsByTagsAndPostStatus(Tag tag, Integer status, Pageable pageable);
@ -207,6 +219,7 @@ public interface PostRepository extends JpaRepository<Post, Long> {
* *
* *
* @param tag tag * @param tag tag
*
* @return List * @return List
*/ */
List<Post> findPostsByTags(Tag tag); List<Post> findPostsByTags(Tag tag);
@ -216,6 +229,7 @@ public interface PostRepository extends JpaRepository<Post, Long> {
* *
* @param keyword * @param keyword
* @param pageable * @param pageable
*
* @return Page * @return Page
*/ */
@Query(value = "SELECT * FROM halo_post WHERE post_status = 0 AND post_type='post' AND post_title LIKE '%=:keyword%' OR post_content LIKE '%=:keyword%'", nativeQuery = true) @Query(value = "SELECT * FROM halo_post WHERE post_status = 0 AND post_type='post' AND post_title LIKE '%=:keyword%' OR post_content LIKE '%=:keyword%'", nativeQuery = true)
@ -225,6 +239,7 @@ public interface PostRepository extends JpaRepository<Post, Long> {
* *
* *
* @param postStatus * @param postStatus
*
* @return List<Post> * @return List<Post>
*/ */
List<Post> findPostsByPostTypeOrderByPostViewsDesc(String postStatus); List<Post> findPostsByPostTypeOrderByPostViewsDesc(String postStatus);
@ -242,6 +257,7 @@ public interface PostRepository extends JpaRepository<Post, Long> {
* *
* @param status * @param status
* @param postType * @param postType
*
* @return * @return
*/ */
Integer countAllByPostStatusAndPostType(Integer status, String postType); Integer countAllByPostStatusAndPostType(Integer status, String postType);
@ -250,8 +266,9 @@ public interface PostRepository extends JpaRepository<Post, Long> {
* *
* *
* @param limit * @param limit
*
* @return List * @return List
*/ */
@Query(value = "SELECT * FROM halo_post WHERE post_status = 0 AND post_type = 'post' ORDER BY post_date DESC LIMIT :limit",nativeQuery = true) @Query(value = "SELECT * FROM halo_post WHERE post_status = 0 AND post_type = 'post' ORDER BY post_date DESC LIMIT :limit", nativeQuery = true)
List<Post> getPostsByLimit(@Param(value = "limit") int limit); List<Post> getPostsByLimit(@Param(value = "limit") int limit);
} }

View File

@ -26,6 +26,7 @@ public interface PostService {
* *
* *
* @param post Post * @param post Post
*
* @return Post * @return Post
*/ */
Post save(Post post); Post save(Post post);
@ -34,6 +35,7 @@ public interface PostService {
* *
* *
* @param postId postId * @param postId postId
*
* @return Post * @return Post
*/ */
Post remove(Long postId); Post remove(Long postId);
@ -43,6 +45,7 @@ public interface PostService {
* *
* @param postId postId * @param postId postId
* @param status status * @param status status
*
* @return Post * @return Post
*/ */
Post updatePostStatus(Long postId, Integer status); Post updatePostStatus(Long postId, Integer status);
@ -58,6 +61,7 @@ public interface PostService {
* *
* *
* @param postType post or page * @param postType post or page
*
* @return List * @return List
*/ */
List<Post> findAll(String postType); List<Post> findAll(String postType);
@ -67,6 +71,7 @@ public interface PostService {
* *
* @param keyWord keyword * @param keyWord keyword
* @param pageable pageable * @param pageable pageable
*
* @return List * @return List
*/ */
List<Post> searchPosts(String keyWord, Pageable pageable); List<Post> searchPosts(String keyWord, Pageable pageable);
@ -77,6 +82,7 @@ public interface PostService {
* @param status 012 * @param status 012
* @param postType post or page * @param postType post or page
* @param pageable * @param pageable
*
* @return Page * @return Page
*/ */
Page<Post> findPostByStatus(Integer status, String postType, Pageable pageable); Page<Post> findPostByStatus(Integer status, String postType, Pageable pageable);
@ -85,6 +91,7 @@ public interface PostService {
* *
* *
* @param pageable pageable * @param pageable pageable
*
* @return Page * @return Page
*/ */
Page<Post> findPostByStatus(Pageable pageable); Page<Post> findPostByStatus(Pageable pageable);
@ -94,6 +101,7 @@ public interface PostService {
* *
* @param status 012 * @param status 012
* @param postType post or page * @param postType post or page
*
* @return List * @return List
*/ */
List<Post> findPostByStatus(Integer status, String postType); List<Post> findPostByStatus(Integer status, String postType);
@ -102,6 +110,7 @@ public interface PostService {
* *
* *
* @param postId postId * @param postId postId
*
* @return Post * @return Post
*/ */
Optional<Post> findByPostId(Long postId); Optional<Post> findByPostId(Long postId);
@ -111,6 +120,7 @@ public interface PostService {
* *
* @param postId postId * @param postId postId
* @param postType postType * @param postType postType
*
* @return Post * @return Post
*/ */
Post findByPostId(Long postId, String postType); Post findByPostId(Long postId, String postType);
@ -120,6 +130,7 @@ public interface PostService {
* *
* @param postUrl * @param postUrl
* @param postType post or page * @param postType post or page
*
* @return Post * @return Post
*/ */
Post findByPostUrl(String postUrl, String postType); Post findByPostUrl(String postUrl, String postType);
@ -132,20 +143,22 @@ public interface PostService {
List<Post> findPostLatest(); List<Post> findPostLatest();
/** /**
* Id *
* *
* @param postDate postDate * @param postDate postDate
* @return List *
* @return Post
*/ */
List<Post> findByPostDateAfter(Date postDate); Post getNextPost(Date postDate);
/** /**
* Id *
* *
* @param postDate postDate * @param postDate postDate
* @return List *
* @return Post
*/ */
List<Post> findByPostDateBefore(Date postDate); Post getPrePost(Date postDate);
/** /**
* *
@ -162,11 +175,12 @@ public interface PostService {
List<Archive> findPostGroupByYear(); List<Archive> findPostGroupByYear();
/** /**
* @return List
*
* @Author Aquan * @Author Aquan
* @Description * @Description
* @Date 2019.1.4 11:14 * @Date 2019.1.4 11:14
* @Param * @Param
* @return List
**/ **/
List<Archive> findAllPost(); List<Archive> findAllPost();
@ -176,6 +190,7 @@ public interface PostService {
* *
* @param year year * @param year year
* @param month month * @param month month
*
* @return List * @return List
*/ */
List<Post> findPostByYearAndMonth(String year, String month); List<Post> findPostByYearAndMonth(String year, String month);
@ -186,6 +201,7 @@ public interface PostService {
* @param year year * @param year year
* @param month month * @param month month
* @param pageable pageable * @param pageable pageable
*
* @return Page * @return Page
*/ */
Page<Post> findPostByYearAndMonth(String year, String month, Pageable pageable); Page<Post> findPostByYearAndMonth(String year, String month, Pageable pageable);
@ -194,6 +210,7 @@ public interface PostService {
* *
* *
* @param year year * @param year year
*
* @return List * @return List
*/ */
List<Post> findPostByYear(String year); List<Post> findPostByYear(String year);
@ -203,6 +220,7 @@ public interface PostService {
* *
* @param category category * @param category category
* @param pageable pageable * @param pageable pageable
*
* @return Page * @return Page
*/ */
Page<Post> findPostByCategories(Category category, Pageable pageable); Page<Post> findPostByCategories(Category category, Pageable pageable);
@ -212,6 +230,7 @@ public interface PostService {
* *
* @param tag tag * @param tag tag
* @param pageable pageable * @param pageable pageable
*
* @return Page * @return Page
*/ */
Page<Post> findPostsByTags(Tag tag, Pageable pageable); Page<Post> findPostsByTags(Tag tag, Pageable pageable);
@ -221,6 +240,7 @@ public interface PostService {
* *
* @param keyword * @param keyword
* @param pageable * @param pageable
*
* @return Page * @return Page
*/ */
Page<Post> searchByKeywords(String keyword, Pageable pageable); Page<Post> searchByKeywords(String keyword, Pageable pageable);
@ -236,6 +256,7 @@ public interface PostService {
* *
* *
* @param post post * @param post post
*
* @return List * @return List
*/ */
List<Post> relatedPosts(Post post); List<Post> relatedPosts(Post post);
@ -251,6 +272,7 @@ public interface PostService {
* *
* *
* @param status * @param status
*
* @return * @return
*/ */
Integer getCountByStatus(Integer status); Integer getCountByStatus(Integer status);
@ -259,6 +281,7 @@ public interface PostService {
* rss * rss
* *
* @param posts posts * @param posts posts
*
* @return String * @return String
*/ */
String buildRss(List<Post> posts); String buildRss(List<Post> posts);
@ -267,6 +290,7 @@ public interface PostService {
* sitemap * sitemap
* *
* @param posts posts * @param posts posts
*
* @return String * @return String
*/ */
String buildSiteMap(List<Post> posts); String buildSiteMap(List<Post> posts);
@ -284,6 +308,7 @@ public interface PostService {
* @param post post * @param post post
* @param cateList cateList * @param cateList cateList
* @param tagList tagList * @param tagList tagList
*
* @return Post Post * @return Post Post
*/ */
Post buildCategoriesAndTags(Post post, List<String> cateList, @RequestParam("tagList") String tagList); Post buildCategoriesAndTags(Post post, List<String> cateList, @RequestParam("tagList") String tagList);
@ -292,6 +317,7 @@ public interface PostService {
* *
* *
* @param limit * @param limit
*
* @return List * @return List
*/ */
List<Post> getRecentPosts(int limit); List<Post> getRecentPosts(int limit);

View File

@ -55,6 +55,7 @@ public class PostServiceImpl implements PostService {
* *
* *
* @param post Post * @param post Post
*
* @return Post * @return Post
*/ */
@Override @Override
@ -67,6 +68,7 @@ public class PostServiceImpl implements PostService {
* *
* *
* @param postId postId * @param postId postId
*
* @return Post * @return Post
*/ */
@Override @Override
@ -82,6 +84,7 @@ public class PostServiceImpl implements PostService {
* *
* @param postId postId * @param postId postId
* @param status status * @param status status
*
* @return Post * @return Post
*/ */
@Override @Override
@ -116,6 +119,7 @@ public class PostServiceImpl implements PostService {
* *
* *
* @param postType post or page * @param postType post or page
*
* @return List * @return List
*/ */
@Override @Override
@ -129,6 +133,7 @@ public class PostServiceImpl implements PostService {
* *
* @param keyWord keyword * @param keyWord keyword
* @param pageable pageable * @param pageable pageable
*
* @return List * @return List
*/ */
@Override @Override
@ -142,6 +147,7 @@ public class PostServiceImpl implements PostService {
* @param status 012 * @param status 012
* @param postType post or page * @param postType post or page
* @param pageable * @param pageable
*
* @return Page * @return Page
*/ */
@Override @Override
@ -153,6 +159,7 @@ public class PostServiceImpl implements PostService {
* *
* *
* @param pageable pageable * @param pageable pageable
*
* @return Page * @return Page
*/ */
@Override @Override
@ -166,6 +173,7 @@ public class PostServiceImpl implements PostService {
* *
* @param status 012 * @param status 012
* @param postType post or page * @param postType post or page
*
* @return List * @return List
*/ */
@Override @Override
@ -178,6 +186,7 @@ public class PostServiceImpl implements PostService {
* *
* *
* @param postId postId * @param postId postId
*
* @return Optional * @return Optional
*/ */
@Override @Override
@ -189,6 +198,7 @@ public class PostServiceImpl implements PostService {
* *
* *
* @param postId postId * @param postId postId
*
* @return Post * @return Post
*/ */
@Override @Override
@ -201,6 +211,7 @@ public class PostServiceImpl implements PostService {
* *
* @param postUrl * @param postUrl
* @param postType post or page * @param postType post or page
*
* @return Post * @return Post
*/ */
@Override @Override
@ -221,28 +232,29 @@ public class PostServiceImpl implements PostService {
} }
/** /**
* *
* *
* @param postDate * @param postDate postDate
* @return List *
* @return Post
*/ */
@Override @Override
public List<Post> findByPostDateAfter(Date postDate) { public Post getNextPost(Date postDate) {
return postRepository.findByPostDateAfterAndPostStatusAndPostTypeOrderByPostDateDesc(postDate, PostStatusEnum.PUBLISHED.getCode(), PostTypeEnum.POST_TYPE_POST.getDesc()); return postRepository.queryNextPost(postDate);
} }
/** /**
* Id *
* *
* @param postDate * @param postDate postDate
* @return List *
* @return Post
*/ */
@Override @Override
public List<Post> findByPostDateBefore(Date postDate) { public Post getPrePost(Date postDate) {
return postRepository.findByPostDateBeforeAndPostStatusAndPostTypeOrderByPostDateAsc(postDate, PostStatusEnum.PUBLISHED.getCode(), PostTypeEnum.POST_TYPE_POST.getDesc()); return postRepository.queryPrePost(postDate);
} }
/** /**
* *
* *
@ -287,11 +299,12 @@ public class PostServiceImpl implements PostService {
} }
/** /**
* @return List
*
* @Author Aquan * @Author Aquan
* @Description * @Description
* @Date 2019.1.4 11:16 * @Date 2019.1.4 11:16
* @Param * @Param
* @return List
**/ **/
@Override @Override
@Cacheable(value = POSTS_CACHE_NAME, key = "'archives_all'") @Cacheable(value = POSTS_CACHE_NAME, key = "'archives_all'")
@ -314,6 +327,7 @@ public class PostServiceImpl implements PostService {
* *
* @param year year * @param year year
* @param month month * @param month month
*
* @return List * @return List
*/ */
@Override @Override
@ -326,6 +340,7 @@ public class PostServiceImpl implements PostService {
* *
* *
* @param year year * @param year year
*
* @return List * @return List
*/ */
@Override @Override
@ -340,6 +355,7 @@ public class PostServiceImpl implements PostService {
* @param year year year * @param year year year
* @param month month month * @param month month month
* @param pageable pageable pageable * @param pageable pageable pageable
*
* @return Page * @return Page
*/ */
@Override @Override
@ -353,6 +369,7 @@ public class PostServiceImpl implements PostService {
* @param category category * @param category category
* @param status status * @param status status
* @param pageable pageable * @param pageable pageable
*
* @return Page * @return Page
*/ */
@Override @Override
@ -367,6 +384,7 @@ public class PostServiceImpl implements PostService {
* @param tag tag * @param tag tag
* @param status status * @param status status
* @param pageable pageable * @param pageable pageable
*
* @return Page * @return Page
*/ */
@Override @Override
@ -380,6 +398,7 @@ public class PostServiceImpl implements PostService {
* *
* @param keyword * @param keyword
* @param pageable * @param pageable
*
* @return Page * @return Page
*/ */
@Override @Override
@ -402,6 +421,7 @@ public class PostServiceImpl implements PostService {
* *
* *
* @param post post * @param post post
*
* @return List * @return List
*/ */
@Override @Override
@ -439,6 +459,7 @@ public class PostServiceImpl implements PostService {
* *
* *
* @param status * @param status
*
* @return * @return
*/ */
@Override @Override
@ -450,6 +471,7 @@ public class PostServiceImpl implements PostService {
* rss * rss
* *
* @param posts posts * @param posts posts
*
* @return String * @return String
*/ */
@Override @Override
@ -467,6 +489,7 @@ public class PostServiceImpl implements PostService {
* sitemap * sitemap
* *
* @param posts posts * @param posts posts
*
* @return String * @return String
*/ */
@Override @Override
@ -494,6 +517,7 @@ public class PostServiceImpl implements PostService {
* @param post post * @param post post
* @param cateList cateList * @param cateList cateList
* @param tagList tagList * @param tagList tagList
*
* @return Post Post * @return Post Post
*/ */
@Override @Override
@ -511,6 +535,7 @@ public class PostServiceImpl implements PostService {
* *
* *
* @param limit * @param limit
*
* @return List * @return List
*/ */
@Override @Override

View File

@ -125,16 +125,17 @@ public class FrontArchiveController extends BaseController {
} }
//获得当前文章的发布日期 //获得当前文章的发布日期
final Date postDate = post.getPostDate(); final Date postDate = post.getPostDate();
//查询当前文章日期之前的所有文章 final Post prePost = postService.getPrePost(postDate);
final List<Post> beforePosts = postService.findByPostDateBefore(postDate); final Post nextPost = postService.getNextPost(postDate);
//查询当前文章日期之后的所有文章 if (null != prePost) {
final List<Post> afterPosts = postService.findByPostDateAfter(postDate); //兼容老版本主题
model.addAttribute("beforePost", prePost);
if (null != beforePosts && beforePosts.size() > 0) { model.addAttribute("prePost",prePost);
model.addAttribute("beforePost", beforePosts.get(beforePosts.size() - 1));
} }
if (null != afterPosts && afterPosts.size() > 0) { if (null != nextPost) {
model.addAttribute("afterPost", afterPosts.get(afterPosts.size() - 1)); //兼容老版本主题
model.addAttribute("afterPost", nextPost);
model.addAttribute("nextPost",nextPost);
} }
List<Comment> comments = null; List<Comment> comments = null;
if (StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.NEW_COMMENT_NEED_CHECK.getProp()), TrueFalseEnum.TRUE.getDesc()) || HaloConst.OPTIONS.get(BlogPropertiesEnum.NEW_COMMENT_NEED_CHECK.getProp()) == null) { if (StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.NEW_COMMENT_NEED_CHECK.getProp()), TrueFalseEnum.TRUE.getDesc()) || HaloConst.OPTIONS.get(BlogPropertiesEnum.NEW_COMMENT_NEED_CHECK.getProp()) == null) {

View File

@ -79,14 +79,14 @@
</div> </div>
<div class="pagination"> <div class="pagination">
<ul class="clearfix"> <ul class="clearfix">
<#if afterPost??> <#if nextPost??>
<li class="pre pagbuttons"> <li class="pre pagbuttons">
<a class="btn" role="navigation" href="/archives/${afterPost.postUrl}" title="${afterPost.postTitle}">上一篇</a> <a class="btn" role="navigation" href="/archives/${nextPost.postUrl}" title="${nextPost.postTitle}">上一篇</a>
</li> </li>
</#if> </#if>
<#if beforePost??> <#if prePost??>
<li class="next pagbuttons"> <li class="next pagbuttons">
<a class="btn" role="navigation" href="/archives/${beforePost.postUrl}" title="${beforePost.postTitle}">下一篇</a> <a class="btn" role="navigation" href="/archives/${prePost.postUrl}" title="${prePost.postTitle}">下一篇</a>
</li> </li>
</#if> </#if>
</ul> </ul>

View File

@ -1,8 +1,8 @@
<nav class="material-nav mdl-color-text--grey-50 mdl-cell mdl-cell--12-col"> <nav class="material-nav mdl-color-text--grey-50 mdl-cell mdl-cell--12-col">
<!-- Prev Nav --> <!-- Prev Nav -->
<#if afterPost??> <#if nextPost??>
<a href="/archives/${afterPost.postUrl!}" id="post_nav-newer" class="prev-content"> <a href="/archives/${nextPost.postUrl!}" id="post_nav-newer" class="prev-content">
<button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon mdl-color--white mdl-color-text--grey-900" role="presentation"> <button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon mdl-color--white mdl-color-text--grey-900" role="presentation">
<i class="material-icons">arrow_back</i> <i class="material-icons">arrow_back</i>
</button> </button>
@ -14,8 +14,8 @@
<div class="section-spacer"></div> <div class="section-spacer"></div>
<!-- Next Nav --> <!-- Next Nav -->
<#if beforePost??> <#if prePost??>
<a href="/archives/${beforePost.postUrl!}" id="post_nav-older" class="next-content"> <a href="/archives/${prePost.postUrl!}" id="post_nav-older" class="next-content">
旧篇 旧篇
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon mdl-color--white mdl-color-text--grey-900" role="presentation"> <button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon mdl-color--white mdl-color-text--grey-900" role="presentation">