gpt4 book ai didi

java - DynamoDBAttribute 上的 AWS DynamoDB 约束

转载 作者:行者123 更新时间:2023-12-02 01:04:52 29 4
gpt4 key购买 nike

我试图根据另一个属性对一个属性施加约束。如果启用状态,则名称必须有一个值。我怎样才能施加约束?使用jdk 8

@DynamoDBTable(tableName = "myTable")
public class MyTable {
private String id;
private State state;//Enabled or Disabled
private String name;//if state is enabled then name property must have a value

public MyTable() {}

public MyTable(final String id) {
this.id = id;
}

@DynamoDBHashKey
public String getId() {
return id;
}

public void setId(final String id) {
this.id = id;
}

public State getState() {
return state;
}

public void setState(final State state) {
this.state = state;
}

public String getName() {
return name;
}

public void setName(final String name) {
this.name = name;
}
}

最佳答案

这只能通过编程来完成:

if ("enabled".equals(myTable.getState()) {
Objects.requireNonNull(myTable.getName(), "Name is missing while state is enabled");
}
mapper.save(myTable);

关于java - DynamoDBAttribute 上的 AWS DynamoDB 约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60201964/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com