手动分页与DynamoDBMapper?

huangapple 未分类评论53阅读模式
英文:

Manual pagination with DynamoDBMapper?

问题

我有一个Java Web应用程序,其中使用DynamoDBMapper来更轻松地在DynamoDB中进行数据持久化。在一个用例中,我有大量的项目,我希望能够在Angular Web应用程序中手动分页浏览。然而,我找到了许多关于DynamoDBMapper支持自动分页的文档(参见这里),其中结果在需要时按需惰性加载。

有没有办法能够手动浏览我的结果呢?也就是说,我想指定一个起始值(可以是索引或上次加载的键),并检索最大数量的结果,以便我可以按照自己的方式分页。我没有找到任何关于如何做到这一点的文档。这种情况是否可能?

英文:

I have a Java web application making use of DynamoDBMapper for easier data persistence within DynamoDB. In one use case I have a very large number of items that I would like to be able to paginate through manually in an Angular web app. However, I've come across numerous documents that talk about DynamoDBMapper's support for automatic pagination (see here) wherein results are lazy-loaded on an as-needed basis.

Is there a way to paginate through my results manually? That is, I'd like to specify a start value (either an index or last-loaded key) and retrieve a maximum number of results so that I can paginate on my own terms. I haven't been able to find any documentation outlining how to do this. Is this possible?

答案1

得分: 0

当您获得一个QueryResultPage或者ScanResultPage时,您会得到getLastEvaluatedKey

返回最后评估的键,可以将其用作exclusiveStartKey以获取下一页的结果。如果这是结果的最后一页,则返回null。

因此,您可以使用getLastEvaluatedKey进行手动分页。

需要注意的是,DynamoDB只返回当前页面的键,这意味着您只能转到下一页。例如,您无法在开始分页之前知道有多少页,也无法跳转到任意页码,而无需迭代浏览每个页面以到达目标页。

英文:

When you get a QueryResultPage or ScanResultPage you get back getLastEvaluatedKey.

> Returns the last evaluated key, which can be used as the exclusiveStartKey to fetch the next page of results. Returns null if this is the last page of results.

So you can use getLastEvaluatedKey to manually page.

Something to note is that Dynamodb only returns the key for the current page, meaning all you can do is go to the next page. You can't, for example, know how many pages you have before starting to page, or skip to an arbitrary page number without iterating through each page to get there.

huangapple
  • 本文由 发表于 2020年4月11日 03:42:06
  • 转载请务必保留本文链接:https://java.coder-hub.com/61147553.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定