Reputation: 127
Can I use Pageable attribute in Spring Data R2dbc repositories with @Query annotation? For example;
public interface PartyRepository extends ReactiveCrudRepository<Party,String> {
@Query("select * from party order by id")
Flux<Party> getParties(Pageable pageable);
}
It gives "org.springframework.data.repository.query.ParameterOutOfBoundsException : Invalid parameter index! You seem to have declared too little query method parameteres!"
Is there any way to use pagination in spring Data R2dbc repositories?
Thanks.
Upvotes: 4
Views: 1658
Reputation: 3108
This is not supported by R2DBC and probably never will.
But you can adjust the query string with SpEL expressions manually to include paging. For MySQL, in your example, this could look like this:
@Query("SELECT * FROM party ORDER BY id LIMIT :#{[0].offset},:#{[0].pageSize}")
Flux<Party> getParties(Pageable pageable);
The [0]
part indicates which argument in your argument list is the Pageable
.
Upvotes: 1