问题
I am trying to do paging and sorting using spring-data-couchbase
but it seems org.springframework.data.couchbase.repository
has only CouchbaseRepository
which is extending CrudRepository<T,ID>
.
There is no interface extending from PagingAndSortingRepository<T,ID>
.
http://docs.spring.io/spring-data/couchbase/docs/1.0.x/api/org/springframework/data/couchbase/repository/CouchbaseRepository.html
I did implement an unconventional solution to the problem setting skip and limit. But want to get total number of page count, which is not available with this solution.
It seems Page<T>
does have .getTotalPages()
回答1:
there is currently no paging support with Spring Data Couchbase, you need to use the lower level API, which is basically the first version of Couchbase's Java SDK.
回答2:
Since Spring-Data-Couchbase 2.0.x support PagingAndSortingRepository
to paging and sorting data.
The interface define:
public interface PagingAndSortingRepository<T, ID extends Serializable>
extends CrudRepository<T, ID> {
Iterable<T> findAll(Sort sort);
Page<T> findAll(Pageable pageable);
}
Paging Project example:
public interface ProjectRepository extends PagingAndSortingRepository<Project, String> {
Page<Project> findByName(String name, Pageable pageable);
}
来源:https://stackoverflow.com/questions/30994744/how-can-i-do-paging-and-sorting-using-spring-data-with-couchbase