使用UUID的java gcloud数据存储密钥
我是使用gcloud数据存储密钥的新手我想知道如何定义使用UUID的密钥
例如在仪器中。下面的java类,如何确保关键对象使用UUID
import java.util.Objects;
import com.google.cloud.datastore.Key;
import org.springframework.cloud.gcp.data.datastore.core.mapping.Entity;
import org.springframework.data.annotation.Id;
@Entity
public class Instrument {
@Id
Key instrumentId;
private String type;
public Instrument(String type) {
this.type = type;
}
public String getType() {
return this.type;
}
public void setType(String type) {
this.type = type;
}
}
# 1 楼答案
你说得对
正如documentation,
A data class must have one and only one field dedicated to storing the primary key of the corresponding datastore entity.
中定义的那样,密钥是数据存储实体的UUID在这种情况下,由于您使用的是Spring框架
org.springframework.cloud.gcp
,要定义哪个属性是键,必须以Datastore Spring framework documentation中指定的方式使用@Id