【发布时间】:2017-07-28 04:05:56
【问题描述】:
我正在尝试从 Amazon AWS 学习 DynamoDB,并且已经能够成功检索数据,但是我很难将其转换为可用的形式。
我的目标是将结果转换为我的 Data 数据类型的 ArrayList,这是一个具有属性、getter 和 setter 的 ValueObject 类。
谢谢!
Map<String,String> expressionAttributesNames = new HashMap<>();
expressionAttributesNames.put("#network_asset_code","network_asset_code");
expressionAttributesNames.put("#temperature","temperature");
Map<String,AttributeValue> expressionAttributeValues = new HashMap<>();
expressionAttributeValues.put(":network_asset_codeValue", new AttributeValue().withS("17AB05"));
expressionAttributeValues.put(":temperature", new AttributeValue().withN("21"));
ScanRequest scanRequest = new ScanRequest()
.withTableName("things")
.withFilterExpression("#network_asset_code = :network_asset_codeValue and #temperature = :temperature")
.withExpressionAttributeNames(expressionAttributesNames)
.withExpressionAttributeValues(expressionAttributeValues);
ScanResult scanResult = client.scan(scanRequest);
List<Map<String,AttributeValue>> attributeValues = scanResult.getItems();
ArrayList<Data> dataArray = new ArrayList<>();
for (Map map: attributeValues) {
Data d = map.values();
dataArray.add(d);
}
【问题讨论】:
标签: list amazon-web-services dictionary arraylist amazon-dynamodb