实际上我正在使用 Slice 在 Cassandra 中的查询中进行分页。我的存储库声明如下:
@Repository
public interface MovementsRepository<T> extends CassandraRepository<Movements, MovementsPK> {
@Query("SELECT movementNumber FROM KEYSPACE.MOVEMENTS)
Slice<Movements> downOrder(@Param("agency") String agency, @Param("account") String account, @Param("initialDate") LocalDate initialDate, @Param("finalDate") LocalDate finalDate, Pageable pageable);
}
我是这样在第一页进行搜索的:
Slice<Movements> slice = this.movementsRepository.downOrder(agency, account, initialDate, finalDate, CassandraPageRequest.first(1000));
要进入下一页,我可以像这样获取属性 slice.nextPageable() :
slice = this.movementsRepository.downOrder(agency, account, initialDate, finalDate, slice.nextPageable());
但是我需要对每个请求进行分页,所以我需要在 JSON 中检索 pagingState 或者当第二个、第三个...请求到来时我是否可以使用它来设置 nextPageable 我知道下一个搜索在下一页中,可以以我正在做的方式或其他方式做这件事? 非常感谢
切片只能导航到下一个切片。 Slice 还提供是否有更多数据要获取的详细信息。所以你可以在 while 循环中运行它,如下所示:
while(slice.hasNext()){
slice = this.movementsRepository.downOrder(agency, account,
initialDate, finalDate, slice.nextPageable());
}