dynamoDB-通过在android中的哈希键中传递值数组来获取多个项目

时间:2019-01-16 12:09:14

标签: android amazon-dynamodb dynamodb-queries

我使用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;

0 个答案:

没有答案