我是靠谱客的博主 淡然百合,这篇文章主要介绍SpringBoot Jpa 分页的一些问题,现在分享给大家,希望可以做个参考。

使用自带默认分页的方式

复制代码
1
2
3
4
5
6
7
@Test public void findAll() { Sort sort = new Sort(Direction.DESC, "id"); Pageable pageable = PageRequest.of(1, 10, sort); Page<User> list = userRepository.findAll(pageable); System.out.println(list); }

使用Query分页的方式

复制代码
1
2
@Query("from User u where u.token=?1 and u.type=2 and u.isDelete=0") Page<User> findUsersByToken(String token, Pageable pageable);

注意:

1、Query中的User必须带别名,否则会报:

unexpected token: where near line 1, column 14 [select count(where) from com.swj.entity.User where token=?1 and type=2 and isDelete=0]

2、Sqlserver需要指定方言版本,否则会报:

java.lang.UnsupportedOperationException: query result offset is not supported

复制代码
1
2
3
4
5
Microsoft SQL Server 2000 -> org.hibernate.dialect.SQLServerDialect Microsoft SQL Server 2005 -> org.hibernate.dialect.SQLServer2005Dialect Microsoft SQL Server 2008 -> org.hibernate.dialect.SQLServer2008Dialect

最后

以上就是淡然百合最近收集整理的关于SpringBoot Jpa 分页的一些问题的全部内容,更多相关SpringBoot内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(47)

评论列表共有 0 条评论

立即
投稿
返回
顶部