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.
- Oracle java 8.
- "org.springframework.boot:spring-boot-gradle-plugin:1.2.3.RELEASE",
- "org.springframework.boot:spring-boot-starter-web",
- "org.springframework.boot:spring-boot-starter-actuator",
- 'org.springframework.boot:spring-boot-starter-mail',
- "org.springframework.boot:spring-boot-starter-thymeleaf",
- "org.springframework.boot:spring-boot-starter-security",
- "org.springframework.security.oauth:spring-security-oauth2:2.0.0.RC2",
- "org.springframework.boot:spring-boot-starter-data-jpa",
- "org.springframework.boot:spring-boot-starter-data-rest",
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);
}