我是dynamo db的新手。我必须执行分页。我必须在HTML页面中显示十条记录。我对Dynamo DB完全陌生。任何人都可以在dynamo db中共享任何用于分页的示例查询。我研究了Amazon dynamo db教程,但我没有任何想法。
我可以使用高级和低级API实现分页吗?有人可以建议从哪里开始吗?
最佳答案
如yegor256建议的那样,您可以将query(QueryRequest)或scan(ScanRequest)与setExclusiveStartKey一起使用。这是如何做的代码片段
HashMap<String, Condition> scanFilter = new HashMap<String, Condition>();
Condition condition = new Condition()
.withComparisonOperator(ComparisonOperator.LT.toString())
.withAttributeValueList(new AttributeValue().withN("100"));
scanFilter.put("column1", condition);
Boolean lastEval = true;
int count = 0;
ScanRequest scanRequest = new ScanRequest(tableName).withScanFilter(scanFilter);
while(lastEval) {
ScanResult scanResult = dynamoDB.scan(scanRequest);
count += scanResult.getCount();
System.out.println("Page Size: " + scanResult.getCount());
System.out.println("Total count = " + count);
if (scanResult.getLastEvaluatedKey() != null)
lastEval = scanResult.getLastEvaluatedKey().isEmpty() == false;
else
lastEval = false;
if (lastEval) {
scanRequest.setExclusiveStartKey(scanResult.getLastEvaluatedKey());
}
}