How can I do paging and sorting using spring data with Couchbase

房东的猫 提交于 2019-12-12 01:24:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!