我正在DynamoDb中进行分页,并且看到结果不符合我的预期,但是我仍然不知道代码中的错误。 我已经搜索了该文档,发现我只需要设置我从上次请求获得的上次评估密钥的评估密钥就可以传递到下一个请求。 这是我的代码:
public QueryResultPage<SbmBookingInfo> getListBooking(String email, int size,
String lastTimeStamp, String lastBookingId, boolean isForward) {
DynamoDBMapper mapper = new DynamoDBMapper(getClient());
Map<String, AttributeValue> expressionAttributeValues = new HashMap<>();
expressionAttributeValues.put(":email", new AttributeValue().withS(email));
if (lastBookingId == null) {
DynamoDBQueryExpression<SbmBookingInfo> queryExpression = new DynamoDBQueryExpression<SbmBookingInfo>()
.withIndexName("practitioner-index").withKeyConditionExpression("email=:email")
.withExpressionAttributeValues(expressionAttributeValues).withConsistentRead(false).withLimit(size);
QueryResultPage<SbmBookingInfo> result = mapper.queryPage(SbmBookingInfo.class, queryExpression);
m_log.info("Last evaluated key " + result.getLastEvaluatedKey());
return result;
} else {
Map<String, AttributeValue> lastEvaluatedKey = new HashMap<>();
lastEvaluatedKey.put("timeStamp", new AttributeValue().withN(lastTimeStamp));
lastEvaluatedKey.put("bookingId", new AttributeValue().withN(lastBookingId));
lastEvaluatedKey.put("email", new AttributeValue().withS(email));
DynamoDBQueryExpression<SbmBookingInfo> queryExpression = new DynamoDBQueryExpression<SbmBookingInfo>().withLimit(size)
.withIndexName("practitioner-index").withKeyConditionExpression("email=:email")
.withExpressionAttributeValues(expressionAttributeValues).withConsistentRead(false)
.withScanIndexForward(isForward).withExclusiveStartKey(lastEvaluatedKey);
m_log.info("Exclusive key" + queryExpression.getExclusiveStartKey());
return mapper.queryPage(SbmBookingInfo.class, queryExpression);
}
}