我使用scanExpression从dynamoDB中获取数据,使用arraylist通过哈希键获取多个数据,但我想将ScanExpression转换为queryExpression
Map<String, String> expressionAttributesNames = new HashMap<>();
expressionAttributesNames.put("#itemId", "itemId");
List<String> queryList = new ArrayList<String>();
Map<String, AttributeValue> expressionAttributeValues = new HashMap<>();
for (int i = 0; i < cartProducts.length(); i++) {
try {
expressionAttributeValues.put(":pointValue" + i, new AttributeValue().withS(cartProducts.getJSONObject(i).getString("itemId")));
queryList.add(":pointValue" + i);
} catch (JSONException e) {
e.printStackTrace();
}
}
CartProductDO cartProductDO = new CartProductDO();
String query = "#itemId IN (" + queryList.toString().replaceAll("[\\[.\\]]", "") + ")";
DynamoDBScanExpression scanExpression = new DynamoDBScanExpression() .withFilterExpression(query) .withExpressionAttributeNames(expressionAttributesNames) .withExpressionAttributeValues(expressionAttributeValues);
列出scanResult = mapper.scan(CartProductDO.class,scanExpression); 返回scanResult;