我正在玩弄 dynamodb 并设置了一个非常简单的表,其中包含 5 个项目,每个项目都有 2 个属性(用户 ID、名称)。然后我通过 java 访问它并将项目输出到终端。相关代码为
ScanRequest scanRequest = new ScanRequest(tableName);
ScanResult scanResult = dynamoDB.scan(scanRequest);
System.out.println("There are " + scanResult.getCount() + " items in this table\n");
System.out.println(scanResult.getItems().get(0).get("userId"));
终端输出为
There are 5 items in this table
{N: 3, }
我只想得到“3”,即只是值而不是值和类型。我知道这是基本的,但我不明白。谢谢!
最佳答案
您需要检索相关的AttributeValue属性(property)。在这种情况下,您的 AttributeValue 是一个数字 {N, 3},因此您将使用
scanResult.getItems().get(0).get("userId").getN()
关于java - 仅从 dynamodb 表中检索项目值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15903569/