【发布时间】:2019-01-22 17:37:52
【问题描述】:
我正在尝试使用 cassandra 实现分页,但我没有在 Stackoverflow 上获得任何成功的解决方案。我得到的突出错误是“对第一个页面以外的页面的分页查询需要具有有效分页状态的 CassandraPageRequest”。请协助。
【问题讨论】:
-
@AmmarAli 请分享示例代码或我如何实现它
标签: spring-boot cassandra pagination
我正在尝试使用 cassandra 实现分页,但我没有在 Stackoverflow 上获得任何成功的解决方案。我得到的突出错误是“对第一个页面以外的页面的分页查询需要具有有效分页状态的 CassandraPageRequest”。请协助。
【问题讨论】:
标签: spring-boot cassandra pagination
您必须使用CassandraPageRequest.of(pageIndex, resultsOnPage)
此外,为了能够对页面使用 findAll 查询,您必须使用 CassandraRepositoy 扩展您的存储库接口以实现查询。
例子:
@Repository
public interface MyRepository extends CassandraRepository<MyModel, MapId>{
}
@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
}
}
【讨论】: