我是Dynamo db的新手。我必须实施分页。我必须在我的html页面中显示十条记录。我对dynamo db完全不熟悉。任何人都可以在dynamo db中共享任何分页示例查询。我学过亚马逊发电机数据库教程,但我没有任何想法。 我可以使用高级和低级api实现分页吗?任何人都可以建议从哪里开始??
答案 0 :(得分:3)
正如yegor256建议的那样,您可以使用查询(QueryRequest)或扫描(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());
}
}
答案 1 :(得分:2)
您应该query(QueryRequest)
或scan(ScanRequest)
使用addExclusiveStartKeyEntry()
另外,请检查此库:jcabi-dynamo