【问题标题】:Springboot cassandra paginationSpringboot cassandra 分页
【发布时间】:2019-01-22 17:37:52
【问题描述】:

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

【问题讨论】:

标签: spring-boot cassandra pagination


【解决方案1】:

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

例子:

  1. 声明一个仓库接口
        @Repository
        public interface MyRepository extends CassandraRepository<MyModel, MapId>{

        }
  1. 注入repo并使用findAll方法和pageable(你必须从页面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
             }
           }

【讨论】:

  • 这会导致错误:原因:java.lang.IllegalArgumentException:无法为除第一页 (0) 之外的索引页面创建 Cassandra 页面请求。有什么解决办法吗?
  • 我忘记编辑答案了...您必须从第一页开始,然后继续
猜你喜欢
  • 2021-01-27
  • 2021-06-22
  • 2019-04-11
  • 2019-02-22
  • 2015-08-08
  • 2015-05-25
  • 1970-01-01
  • 1970-01-01
  • 2021-08-06
相关资源
最近更新 更多