Reputation: 69
I've looked at both this and this question. But I have still not been able to setup paging for a repository method. Not sure if I'm affected by a bug or simply not writing this correctly. Basically I'm asking if someone could provide an example of how to implement paging on a repository method which gets exported through the @RepositoryRestResource annotation?
My attempt at achieving pagination
@RepositoryRestResource(collectionResourceRel = "users", path = "users")
public interface UserRepository extends JpaRepository<User, Long> {
Page<User> findByUserGroup(@Param("userGroup") String userGroup,
@Param("page") Pageable pageable);
}
The error message generated by the code
Offending method public abstract org.springframework.data.domain.Page com.project.repository.UserRepository.findByUserGroup(java.lang.String,java.awt.print.Pageable)
I've also tried removing the method param for pageable which then resulted in this error:
Caused by: java.lang.IllegalArgumentException: Either use @Param on all parameters except Pageable and Sort typed once, or none at all!
Dependencies I'm using in this project.
Any help would be greatly appreciated.
Update: The final solution
Adding this as reference for anyone else wondering how to do this. The main difference was that I had to make sure to import the right Pageable
object as noted in the chosen answer.
@RepositoryRestResource(collectionResourceRel = "users", path = "users")
public interface UserRepository extends JpaRepository<User, Long> {
Page<User> findByUserGroup(@Param("userGroup") String userGroup, Pageable pageable);
}
Upvotes: 6
Views: 7961
Reputation: 2116
Seems little late but their is easier solution for pagination. See below code snippet.
public interface NotebookRepository extends PagingAndSortingRepository<Notebook, Long> {
For complete example please go through this blog
Upvotes: 0
Reputation: 6306
You are using the Pageable class from the wrong package: java.awt.print.Pageable
. You should be using org.springframework.data.domain.Pageable
Upvotes: 14