0

Is there a way to ask for a result to be sorted but not paginated ?

I have this:

public interface SampleRepository extends PagingAndSortingRepository<Sample, Integer> {
}

but when calling http://localhost:8080/data/samples?sort=name,desc the result is automatically paginated, but I do not want it paginated.

Ignacio
  • 331
  • 6
  • 15
  • Possible duplicate of [How to disable paging for JpaRepository in spring-data-rest](https://stackoverflow.com/questions/31379902/how-to-disable-paging-for-jparepository-in-spring-data-rest) – Alan Hay Jun 22 '18 at 11:27

1 Answers1

1

PagingAndSortingRepository offers the Iterable<T> findAll(Sort sort) method, that Returns all entities sorted by the given options.

Simply declare your SampleRepository like this:

public interface SampleRepository extends PagingAndSortingRepository<Sample, Integer> {
    List<Sample> findAll(Sort sort)
}

That's what JpaRepository does, for instance.

http://localhost:8080/data/samples?sort=name,desc should then be mapped against SampleRepository.findAll(Sort sort) and beahve as you want it to.

If it's not the case, you can also add a findBy* method:

@RestResource(path = "asList", rel = "asList")
public List<Sample> findAllAsList(Sort sort);

and call http://localhost:8080/data/samples/search/asList/samples?sort=name,desc

Marc Tarin
  • 3,109
  • 17
  • 49
  • Thanks I'll test and comment, I saw the method is already declared on the inherit repositories actually but the paginated version is taking over the Slice one even if the pagination parameters are not included, may be as you suggested the explicit declaration will take precedence over the other (will try). – Ignacio Jun 24 '18 at 14:14