我是DynamoDB的新手,想知道如何使用hashKey和sortKey在DynamoDB的表上查询。如何根据分区键和排序键[Java]查询DynamoDB?
我有一张名为Items
的表格。它`模式是
1. Product (Partition Key of type String)
2. ID (Sort Key of type int)
3. Date (attribute of type String)
我为获得具有product = 10
所有项目查询
Items it = new Items();
it.setProduct("apple");
DynamoDBQueryExpression<Items> queryExpression = new DynamoDBQueryExpression<Items>()
.withHashKeyValues(it);
List<Items> itemList = mapper.query(Items.class, queryExpression);
但是,现在我想有Product = "apple"
和ID = 100
所有项目。
我可以在Java
中为DynamoDB
写一个查询。
我得到一个错误说,表;没有用于RANGE键的映射 –
ID是排序键而不是范围键。 –
用模型类更新了答案。同样,您也可以定义非关键属性。但是为了加载工作,非关键属性不是必需的。排序键被称为范围键 – notionquest