我尝试在本地的AWS Dynamo教程中运行以下示例,Step 3: Put, Update, and Delete an Item。
就我而言,它是:
val client: AmazonDynamoDBClient = new AmazonDynamoDBClient().withEndpoint("http://localhost:7777")
val dynamoDB: DynamoDB = new DynamoDB(client)
val table: Table = dynamoDB.getTable("Catalog")
try {
val rating: java.util.List[Float] = new java.util.LinkedList[Float]()
rating.add(1)
val newItem: Item = new Item().withPrimaryKey("Title", "Title here").withInt("Country", 1).
withList("Ratings", rating)
val outcome: PutItemOutcome = table.putItem(newItem)
System.out.println("PutItem succeeded:\n" + outcome.getPutItemResult)
} catch {
case exception: Exception => System.out.println(exception.getMessage)
}
输出结果为:
PutItem成功:{}
在本地DynamoDB控制台中:
var params = {
TableName: "Catalog",
Key: {
"Title":"Title Here",
}
};
docClient.get(params, function(err, data) {
if (err)
console.log(JSON.stringify(err, null, 2));
else
console.log(JSON.stringify(data, null, 2));
});
输出:
{ " Item":{ "标题":"标题在这里", "评级":[ 1 ] "国家":1 } }
答案 0 :(得分:0)
您需要在PutItem请求中将ReturnValues
设置为ALL_OLD
以获取返回的值,但即使这样,它也只会包含已替换的值。
使用您的代码,您需要执行诸如替换
之类的操作val outcome: PutItemOutcome = table.putItem(newItem)
与
val putItemSpec: PutItemSpec = new PutItemSpec()
.withItem(newItem)
.withReturnValues(ReturnValue.ALL_OLD)
val outcome: PutItemOutcome = table.putItem(putItemSpec)