小编Nad*_*med的帖子

如何使用hibernate在spring boot中实现分页

我正在使用带有hibernate的spring boot,我想在我的项目中使用分页.我在谷歌上搜索并看到很多例子,但我无法在我的项目中实现它.

我想如果我在我的网址中传递1然后10个结果应该来,如果我传递2然后接下来10个结果应该来,依此类推.

这是我的

@Transactional
public interface PostDao extends CrudRepository<Post, Long>{

@Query(getAllPostsByRank)
List<Post> getAllPostsByRank();

final String getAllPostsByRank= "from Post order by value DESC";
}
Run Code Online (Sandbox Code Playgroud)

这是我的控制器

@RequestMapping("/top")
    @ResponseBody 
     public List<Post> getAllPosts(HttpServletRequest req, HttpServletResponse res) throws ServletException {

List<Post> postobj = postDao.getAllPostsByRank();
return postobj;
}
Run Code Online (Sandbox Code Playgroud)

这是我的网址:

http://localhost:8888/v1.0/post/top/1
Run Code Online (Sandbox Code Playgroud)

请建议.

java pagination hibernate hql spring-boot

13
推荐指数
4
解决办法
3万
查看次数

标签 统计

hibernate ×1

hql ×1

java ×1

pagination ×1

spring-boot ×1