记录一下Springboot中使用SpringDataJPA查询最新数据
我是以Id降序排序的
public interface BlogRepository extends JpaRepository<Blog, Long>{
//最新数据
Page findByOrderByIdDesc(Pageable pageable);
}
BlogService中
listTop5NewestBlogs()
BlogServiceImpl中
@Override
public List listTop5NewestBlogs() {
return blogRepository.findByOrderByIdDesc(TOP_5_PAGEABLE).getContent();
}