[英]Azure Cosmos DB with SpringBoot Java - Paginate by page number and size
有沒有更好的按頁碼和大小分頁的方法? 我正在經歷下面的例子,
public List<Volcano> getAllVolcanoesByPage(Integer pageNo, Integer pageSize, String sortBy) {
final Pageable pageable = new CosmosPageRequest(0, pageSize, null);
List<Volcano> content = null;
Page<Volcano> page = this.repository.findAll(pageable);
if (pageNo == 0) {
content = page.getContent();
for (Volcano volcano : content) System.out.println(volcano.toString());
return content;
} else {
Page<Volcano> nextPage = null;
for (int i = 1; i <= pageNo; i++) {
nextPage = this.repository.findAll(page.getPageable());
/* reset page to nextpage like a linkedlist*/
page = nextPage;
content = nextPage.getContent();
for (Volcano volcano : content) System.out.println(volcano.toString());
}
return content;
}
}
上面的實現迭代每個頁面直到請求的數量,當數量和大小增加時,這會影響性能。 我知道我們可以使用continuationToken
獲取下一組記錄,但是有沒有更好的方法來處理頁碼和大小?
@Query("select * from c offset @offset limit @limit")
您可能需要計算偏移量和限制,但之后這可能會起作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.