本文介绍了Java中的DynamoDb分页查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是dynamo db的新手。我必须执行分页。我必须在我的html页面中显示十条记录。我对Dynamo DB完全陌生。任何人都可以在dynamo db中共享任何用于分页的示例查询。我研究了Amazon dynamo db教程,但我没有任何想法。
我可以使用高级和低级api实现分页吗?

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??

推荐答案

如yegor256建议的那样,您可以使用query(QueryRequest)或scan(ScanRequest)改为使用 setExclusiveStartKey 。这是操作方法的代码段

As yegor256 suggested, you could use query(QueryRequest) or scan(ScanRequest) with setExclusiveStartKey instead. Here's a code snippet of how to do it

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());
    }
}

这篇关于Java中的DynamoDb分页查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 14:39