【发布时间】:2016-11-10 04:39:15
【问题描述】:
假设我有一个枚举:
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。并考虑使用publicgetter 将value字段声明为private。
标签: java spring hibernate jpa enums