【发布时间】:2018-11-23 16:25:09
【问题描述】:
我被要求创建一个名为Type 的列varchar2(1),其值为partial 或all
我在 Model.Java
中所做的 @Column(name="TYPE")
@Enumerated(EnumType.STRING)
public TypeEnum getType() {
return type;
}
public void setType(TypeEnum type) {
this.type = type;
}
这是我的 TypeEnum.java
public enum TypeEnum {
ALL(0, "all"),
PARTIAL(1, "partial");
private int code;
private String value;
private TypeEnum(int code, String value) {
this.code = code;
this.value = value;
}
public String getValue() {
return value;
}
public int getCode() {
return code;
}
public static TypeEnum getTypeEnum(String value){
TypeEnum[] types = values();
for(int i=0; i<types.length; i++){
TypeEnum type = types[i];
if(value.equals(type.getValue()))
return type;
}
return null;
}
}
那么如何在DB中存储TypeEnum来实现varchar2(1)
【问题讨论】: