繁体   English   中英

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

[英]Using contains filter in DynamoDB scan with Java - android

我有 aws dynamo db 表,如下所示。 在此处输入图像描述

现在我想按如下方式过滤它。 在此处输入图像描述

为此,我使用了以下代码,并且在我的代码中得到 0 个结果。我的代码有什么问题。如何修复它?

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

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

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

尝试这样的事情:

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);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM