我了解我们需要为DDB的BatchGetItem传递属性名称和主键名称。喜欢:
TableKeysAndAttributes forumTableKeysAndAttributes = new TableKeysAndAttributes(forumTableName);
// Add a partition key
forumTableKeysAndAttributes.addHashOnlyPrimaryKeys("Animal", "cat", "dog");
BatchGetItemOutcome outcome = dynamoDB.batchGetItem(forumTableKeysAndAttributes,threadTableKeysAndAttributes);
因此,此处我们手动传递属性名称“ animal”和两个主键(两种类型的动物:狗和猫)。 (如果我错了,请纠正我)
但是,如果现在我有一个主键列表,即[dog, cat, cow, rabbit, sheep, chicken...]
,它以List<String>
的形式出现,显然我不能手动传递它们,那该怎么办?
谢谢!
答案 0 :(得分:1)
假设您有一个哈希键列表:
List<String> keys
您可以像这样调用addHashOnlyPrimaryKeys
方法:
forumTableKeysAndAttributes.addHashOnlyPrimaryKeys("Animal", keys.toArray(new String[keys.size()]));
您在这里提出的问题基本上是将列表作为参数传递给vararg方法。