Pageable custom queries with Spring Data JPA

In previous posts I explained how you can use Spring Data JPA to create repositories that support custom queries, as well as to support paging in your app. You might wonder whether you can use these together.

The answer is yes. It works just like you would expect:

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;

public interface IncidentRepo extends JpaRepository<Incident, Long> {

    Page<Incident> findByProblemId(Long problemId, Pageable pageable);
}
This entry was posted in Chapter 02 - Data, Quick Tips and tagged , , , . Bookmark the permalink.

2 Responses to "Pageable custom queries with Spring Data JPA"

Leave a reply