代码之家  ›  专栏  ›  技术社区  ›  LookIntoEast

DynamoDB关键变量列表的BatchGetItem

  •  0
  • LookIntoEast  · 技术社区  · 7 年前

    我知道我们需要为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)(如果我错了,请纠正我)

    但是如果现在我有一个主键列表,那就是 [dog, cat, cow, rabbit, sheep, chicken...] 它的形式是 List<String>

    谢谢!

    1 回复  |  直到 7 年前
        1
  •  2
  •   Apoorv Agarwal    7 年前

    List<String> keys
    

    你可以打电话给 addHashOnlyPrimaryKeys 方法如下:

    forumTableKeysAndAttributes.addHashOnlyPrimaryKeys("Animal", keys.toArray(new String[keys.size()]));