Getter用于在dynamoDB中添加值

问题描述 投票:0回答:1

我有一个称为Attribute的属性,该属性在dynamoDB中设置(不是必需的),所有属性值将通过api发送,该api将添加到dynamoDB中。我正在使用

@DynamoDBAttribute(attributename = Attribute)
private set<String> Attribute

public Set<String> getAttribute() {
     if(CollectionUtils.isNullOrEmpty(Attribute)) {
         return ImmutableSet.of(DEFAULT_ATTRIBUTE);
     } else {
         return ImmutableSet.copyOf(Attribute);
     }
}

public void setAttribute(final Set<String> Attribute) {
    if (CollectionUtils.isNullOrEmpty(Attribute)) {
        this.categories = ImmutableSet.of();
    } else {
        this.categories = ImmutableSet.copyOf(Attribute);
    }
}

我期望我们在未使用的请求中传递属性值时,我的dynamoDB表具有空集,但与此相反,它是将DEFAULT_ATTRIBUTE保存为字段Attribute的值。

我的DynamoDBMapperConfig.Savebehavior具有默认的UPDATE,但是我看到在保存新值时,所有Savebehavior的工作方式都相同。

[如果有人知道这个问题,请帮我解决这个问题,我已经尝试了很长时间了。我想知道为什么getAttribute中的值被存储为Attribute值?

java set amazon-dynamodb crud getter-setter
1个回答
0
投票

尝试以下方法:

private set<String> Attribute

@DynamoDBTyped(DynamoDBMapperFieldModel.DynamoDBAttributeType.SS)
public Set<String> getAttribute() {
     return Attribute;
}

public void setAttribute(final Set<String> Attribute) {
    this.Attribute = Attribute;
}

DynamoDBMapper将为您处理字符串集。您只需要使用正确的注释。https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBMapper.DataTypes.html

© www.soinside.com 2019 - 2024. All rights reserved.