I might be possible to implement easier with a help of specification but do not know because I am a bit unsure what you actually need. Anyway, see the following repository, a specification on it and especially what interfaces it implements:
public interface SomeEntityRepository extends Repository,
PagingAndSortingRepository, JpaSpecificationExecutor {
@SuppressWarnings("serial")
public static Specification findByCountryIdSpecification(Long countryId) {
return new Specification() {
@Override
public Predicate toPredicate(Root root, CriteriaQuery> query,
CriteriaBuilder criteriaBuilder) {
// implement query logic with "countryId" here
return null;
}
};
}
// there will be a method like below with JpaSpecificationExecutor
// Page findAll(Specification specification, Pageable pageable);
}
With correctly designed specification the usage of pageable is easy:
repo.findAll(SomeEntityRepository.findByCountryIdSpecification(countryId), pageable);