我已在本地 dynamoDB 中创建了一个表。这些字段是,
id (N)
name (S)
school (S)
classname (S)
现在我想检索学校等于“xschool”的所有记录并打印。
尝试了下面的代码,但它在查询中给了我一个错误,
QuerySpec spec = new QuerySpec().withProjectionExpression("sid, classname, school")
.withKeyConditionExpression("school = :v_school").
withValueMap(new ValueMap().withString(":v_school", "abcschool"));
ItemCollection<QueryOutcome> items = table.query(spec);
Iterator<Item> iterator = items.iterator();
while (iterator.hasNext()) {
System.out.println(iterator.next().toJSONPretty());
}
因为我是 dynamoDB 的新手,所以对此有何建议。
最佳答案
AmazonDynamoDB dynamoDBClient = createClient();
DynamoDB dynamoDB = new DynamoDB(dynamoDBClient);
String tableName = "student";
Table table = dynamoDB.getTable(tableName);
Map<String, Object> expressionAttributeValues = new HashMap<String, Object>();
expressionAttributeValues.put(":sc", schoolname);
ItemCollection<ScanOutcome> items = table.scan("school = :sc", // FilterExpression
"sid, school, firstname, classname", // ProjectionExpression
null, // ExpressionAttributeNames - not used in this example
expressionAttributeValues);
Iterator<Item> iterator = items.iterator();
while (iterator.hasNext()) {
System.out.println(iterator.next().toJSONPretty());
}
试试这个,我想这对你有用
关于java - 在java中从DynamoDB本地检索选定的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51930080/