Pagination Spring boot:如何在@RepositoryRestResource上配置分页?

Pagination Spring boot:如何在@RepositoryRestResource上配置分页?,pagination,spring-boot,spring-data-jpa,spring-data-rest,Pagination,Spring Boot,Spring Data Jpa,Spring Data Rest,我已经看过和了。但我仍然无法为存储库方法设置分页。不确定我是否受到bug的影响,或者只是写得不正确。基本上,我是问是否有人可以提供一个示例,说明如何在通过@RepositoryRestResource注释导出的存储库方法上实现分页 实现分页的尝试 @RepositoryRestResource(collectionResourceRel = "users", path = "users") public interface UserRepository extends JpaRepository

我已经看过和了。但我仍然无法为存储库方法设置分页。不确定我是否受到bug的影响,或者只是写得不正确。基本上,我是问是否有人可以提供一个示例,说明如何在通过@RepositoryRestResource注释导出的存储库方法上实现分页

实现分页的尝试

@RepositoryRestResource(collectionResourceRel = "users", path = "users")
public interface UserRepository extends JpaRepository<User, Long> {

    Page<User> findByUserGroup(@Param("userGroup") String userGroup,
                                            @Param("page") Pageable pageable);

}
我还尝试删除pageable的方法param,这导致了以下错误:

Caused by: java.lang.IllegalArgumentException: Either use @Param on all parameters except Pageable and Sort typed once, or none at all!
我在这个项目中使用的依赖项

  • oraclejava8
  • “org.springframework.boot:springboot gradle插件:1.2.3.RELEASE”
  • “org.springframework.boot:springbootstarterweb”
  • “org.springframework.boot:springbootstarteractor”
  • 'org.springframework.boot:springbootstartermail'
  • “org.springframework.boot:springbootstartermyleaf”
  • “org.springframework.boot:springbootstartersecurity”
  • “org.springframework.security.oauth:spring-security-oauth2:2.0.0.RC2”
  • “org.springframework.boot:springbootstarterdatajpa”
  • “org.springframework.boot:springbootstarterdatarest”
  • 任何帮助都将不胜感激

    更新:最终解决方案

    添加此项作为其他想知道如何执行此操作的人的参考。主要区别在于,我必须确保导入正确的
    Pageable
    对象,如所选答案中所述

    @RepositoryRestResource(collectionResourceRel = "users", path = "users")
    public interface UserRepository extends JpaRepository<User, Long> {
    
        Page<User> findByUserGroup(@Param("userGroup") String userGroup, Pageable pageable);
    
    }
    
    @RepositoryRestResource(collectionResourceRel=“users”,path=“users”)
    公共接口用户存储库扩展了JpaRepository{
    Page findByUserGroup(@Param(“userGroup”)字符串userGroup,Pageable Pageable);
    }
    
    您使用的可分页类来自错误的包:
    java.awt.print.Pageable
    。您应该使用
    org.springframework.data.domain.Pageable

    似乎有点晚了,但它们的分页解决方案更简单。请参阅下面的代码片段

    public interface NotebookRepository extends PagingAndSortingRepository<Notebook, Long> {
    
    公共接口NotebookRepository扩展了分页和排序存储库{
    

    作为完整的例子,请仔细阅读这个

    发现得很好!这正是问题所在。谢谢!:)我可以看到人们访问我的博客,如果这个解决方案有效,请投票。
    public interface NotebookRepository extends PagingAndSortingRepository<Notebook, Long> {