1

I am new to dynamo db. I have to implement pagination. I have to show ten records in my html page. I am completely new to dynamo db. Can any one share any sample query for pagination in dynamo db. I have studied amazon dynamo db tutorial but i did not get any idea. Can i implement pagination using highlevel and lowlevel api? can any one suggest where to start??

4

2 回答 2

3

正如 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());
    }
}
于 2015-07-08T19:22:47.493 回答
2

你应该使用query(QueryRequest)or scan(ScanRequest)withaddExclusiveStartKeyEntry()

另外,检查这个库:jcabi-dynamo

于 2013-07-14T10:29:26.003 回答