DynamoDB映射器“ batchLoad()”输入

Aru*_*shi 2 amazon-dynamodb

我只是在使用dynamoDB的batchLoad函数。在这里, 函数的文档说,它需要的输入是List<KeyPair>。但是,当我使用KeyPair对象时,会引发错误,认为参数应为dynamodb annotated class

我可以使用DynamoDB类,在该类中,我仅设置hashKey and rangeKey类的属性并将其作为参数传递。但现在我的用例是Class(带注释的DynamoDB),我正在使用has @NonNull字段。如果必须为此传递参数,则必须在其中设置垃圾值,这显然是不可取的。有什么帮助/建议吗?谢谢!

not*_*est 6

这是工作示例。

摘要:-

  • 模型类-应该是地图的关键
  • keyPairList-您想检索的密钥对列表

与模特班:-

Map<Class<?>, List<KeyPair>> keyPairForTable = new HashMap<>();
            keyPairForTable.put(Movies.class, keyPairList);
Run Code Online (Sandbox Code Playgroud)

完整代码:-

public Boolean batchLoadMoviesUsingKeyPair() {

    DynamoDBMapper dynamoDBMapper = new DynamoDBMapper(dynamoDBClient);

    KeyPair keyPair1 = new KeyPair();
    keyPair1.withHashKey(1991);
    keyPair1.withRangeKey("Movie with map attribute");

    KeyPair keyPair2 = new KeyPair();
    keyPair2.withHashKey(2010);
    keyPair2.withRangeKey("The Big New Movie 2010");

    List<KeyPair> keyPairList = new ArrayList<>();
    keyPairList.add(keyPair1);
    keyPairList.add(keyPair2);

    Map<Class<?>, List<KeyPair>> keyPairForTable = new HashMap<>();
    keyPairForTable.put(Movies.class, keyPairList);

    Map<String, List<Object>> batchResults = dynamoDBMapper.batchLoad(keyPairForTable);

    for (Map.Entry<String, List<Object>> entry : batchResults.entrySet()) {
        System.out.println(entry.getKey());
        System.out.println(entry.getValue());
    }

    return true;

}
Run Code Online (Sandbox Code Playgroud)