在 Java - android 的 DynamoDB 扫描中使用包含过滤器

Using contains filter in DynamoDB scan with Java - android

我有 aws dynamo db table 如下。

现在我想过滤如下。

为此,我使用了以下代码,但在我的 code.what 中得到 0 个结果,我的 code.how 要修复它吗?

public ScanResult getAllMemos() {
    ScanRequest scanRequest = new ScanRequest()
            .withTableName(DB_NAME)
            .withFilterExpression("contains(imgName,thumbnail)");
    return util.getAmazonDynamoDBClient(getActivity()).scan(scanRequest);
}

没有过滤器表达式我得到所有结果。

就像评论中讨论的那样,您需要使用过滤器的值创建一个表达式属性值映射并使用它。

尝试这样的事情:

public ScanResult getAllMemos() {

    Map<String, AttributeValue> expressionAttributeValues =
        new HashMap<String, AttributeValue>();
    expressionAttributeValues.put(":val", new AttributeValue().withS("thumbnail"));


    ScanRequest scanRequest = new ScanRequest()
            .withTableName(DB_NAME)
            .withFilterExpression("contains(imgName,:val)")
            .withExpressionAttributeValues(expressionAttributeValues);
    return util.getAmazonDynamoDBClient(getActivity()).scan(scanRequest);
}