Fix native query error

pull/137/head
johnniang 2019-03-05 00:12:18 +08:00
parent 015fb3c399
commit a0779ae11e
3 changed files with 13 additions and 13 deletions

View File

@ -154,13 +154,11 @@ public class Post implements Serializable {
/**
* Post priority (default is 0)
*/
@ColumnDefault("0")
private Integer postPriority;
/**
*
* (default is admin)
*/
@ColumnDefault("admin")
private String postSource;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
@ -189,6 +187,10 @@ public class Post implements Serializable {
postPriority = 0;
}
if (postSource == null) {
postSource = "admin";
}
postId = null;
}
}

View File

@ -24,14 +24,6 @@ import java.util.List;
*/
public interface PostRepository extends BaseRepository<Post, Long>, JpaSpecificationExecutor<Post> {
/**
*
*
* @return List
*/
@Query(value = "SELECT * FROM halo_post WHERE post_type='post' ORDER BY post_date DESC LIMIT 5", nativeQuery = true)
List<Post> findTopFive();
/**
*
*

View File

@ -3,10 +3,10 @@ package cc.ryanc.halo.service.impl;
import cc.ryanc.halo.model.domain.Category;
import cc.ryanc.halo.model.domain.Post;
import cc.ryanc.halo.model.domain.Tag;
import cc.ryanc.halo.model.support.Archive;
import cc.ryanc.halo.model.enums.BlogPropertiesEnum;
import cc.ryanc.halo.model.enums.PostStatusEnum;
import cc.ryanc.halo.model.enums.PostTypeEnum;
import cc.ryanc.halo.model.support.Archive;
import cc.ryanc.halo.repository.PostRepository;
import cc.ryanc.halo.service.CategoryService;
import cc.ryanc.halo.service.PostService;
@ -18,7 +18,9 @@ import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
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.data.jpa.domain.Specification;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Service;
@ -238,7 +240,11 @@ public class PostServiceImpl extends AbstractCrudService<Post, Long> implements
@Override
@Cacheable(value = POSTS_CACHE_NAME, key = "'posts_latest'")
public List<Post> findPostLatest() {
return postRepository.findTopFive();
Pageable pageable = PageRequest.of(0, 5, Sort.by(Sort.Direction.DESC, "postDate"));
Page<Post> postPage = postRepository.findAll(pageable);
return postPage.getContent();
}
/**