Spring in Practice

Willie Wheeler's Spring blog

Pageable Custom Queries With Spring Data JPA

| Comments

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);