我正在尝试使用 cassandra 实现分页,但我在 Stackoverflow 上没有得到任何成功的解决方案。我遇到的突出错误是“第一个页面以外的页面的分页查询需要具有有效分页状态的 CassandraPageRequest”。请协助。
最佳答案
您必须使用CassandraPageRequest.of(pageIndex, resultsOnPage)
另外,为了能够在页面中使用 findAll 查询,您必须使用 CassandraRepositoy
扩展存储库接口(interface)以实现查询。
示例:
- 声明存储库接口(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/