Kev*_*Dev 5 java amazon-dynamodb aws-sdk
我正在尝试使用 Java SDK 在 DynamoDB 中实现分页。
我有一个简单的数据模型,一个HashKey
id 和一个日期为RangeKey
. 我想查询给定日期之后的所有日期。到目前为止,这有效,但问题是使用最后一个评估键的分页部分。
查询最后一页时,lastEvaluatedKey
不为空,仍指向查询的最后一页的最后一项。使用此键设置的另一个查询èxclusiveStartKey
则返回 0 结果,带有null
lastEvaluatedKey
.
我的代码如下所示:
var query = new DynamoDBQueryExpression<DynamoModel>();
var keyCondition = ImmutableMap.<String, AttributeValue>builder()
.put(":v_userid", new AttributeValue().withS(userId))
.put(":v_date", new AttributeValue().withS(date.toString()))
.build();
if (!StringUtils.isEmpty(lastKey)) {
query.setExclusiveStartKey(ImmutableMap.<String, AttributeValue>builder()
.put("userId", new AttributeValue().withS(userId))
.put("date", new AttributeValue().withS(lastKey)).build());
}
query.withKeyConditionExpression("userId = :v_userid AND date >= :v_date");
query.withExpressionAttributeValues(keyCondition);
query.setLimit(2);
QueryResultPage<DynamoModel> resultPage = mapper.queryPage(DynamoModel.class, query);
Run Code Online (Sandbox Code Playgroud)
有人知道为什么lastEvaluatedKey
在到达与 匹配的最后一个项目时 不为空KeyCondition
吗?当我只保存符合条件的项目时,LastEvaluatedKey
正如预期的那样为空。
归档时间: |
|
查看次数: |
6448 次 |
最近记录: |