spring-boot - Springboot cassandra 分页

标签 spring-boot cassandra pagination

我正在尝试使用 cassandra 实现分页,但我在 Stackoverflow 上没有得到任何成功的解决方案。我遇到的突出错误是“第一个页面以外的页面的分页查询需要具有有效分页状态的 CassandraPageRequest”。请协助。

最佳答案

您必须使用CassandraPageRequest.of(pageIndex, resultsOnPage) 另外,为了能够在页面中使用 findAll 查询,您必须使用 CassandraRepositoy 扩展存储库接口(interface)以实现查询。

示例:

  1. 声明存储库接口(interface)
        @Repository
        public interface MyRepository extends CassandraRepository<MyModel, MapId>{

        }
  • 注入(inject)存储库并使用可分页的 findAll 方法(必须从第 0 页开始)
  •            @Autowired
                private MyRepo repo;
    
                void someMethod(){
                 int resultOnPage = ...
                 //this is the first page
                 Slice<MyModel> page= repository.findAll(CassandraPageRequest.of(0, resultOnPage ));
                 // iterate the slice with iterator
                 //.......
    
                 //go ahead and take the next pages
                 while (page.hasNext()) {
                   page = repository.findAll(page.nextPageable());
                   //process the page iterating it
                 }
               }
    
    

    关于spring-boot - Springboot cassandra 分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51865542/

    相关文章:

    javascript - CSS 和 Javascript 不呈现 404 错误 spring-boot

    mysql - 对于给定的设计目标,Google Cloud SQL 与 Google Cloud Datastore 的优缺点

    jquery - 分页表通过选择选项显示 TR

    twitter-bootstrap - flask-paginate pagination.links 样式问题

    spring - 为什么我们需要在 spring-boot-starter-jersey 项目中为 Jersey 资源提供 @Component spring 注解?

    spring-boot - 如何在 Spring Boot 中设置同站 cookie 标志?

    spring-boot - Spring boot 中配置服务器的多个搜索路径

    database - 为什么不像通常使用 MySQL 那样从 "single & small"Cassandra 服务器开始呢?

    java - 更新 Titan 图数据库中的顶点属性的问题

    php - 挣扎于 PHP/MySQL 分页