说我有一个枚举:贮藏枚举值与JPA
public enum NotificationType {
Store("S"),
Employee("E"),
Department("D"),
All("A");
public String value;
NotificationType(String value) {
this.value = value;
}
}
我想存储S
或E
而非Store
或Employee
在数据库中。目前,我已将它映射到实体中,如下所示:
@Enumerated(EnumType.STRING)
private NotificationType notificationType;
但是如果可能的话,不确定如何获得我想要的。
只是想说明一下,你的枚举是可变的,建议使枚举字段为final。并考虑用'public' getter声明字段'value'为'private'。 –