Tôi có enum này:tên enum Store, không giá trị trong cơ sở dữ liệu sử dụng EBean
public enum DocumentTypes {
PDF("PDF Document"), JPG("Image files (JPG)"), DOC("Microsoft Word documents");
private final String displayName;
DocumentTypes(final String display) {
this.displayName = display;
}
@Override
public String toString() {
return this.displayName;
}
}
Và một mô hình như thế này:
@Entity
@Table(name = "documents")
public class Document extends Model {
@Id
public Long id;
@Constraints.Required
@Formats.NonEmpty
@Enumerated(EnumType.STRING)
@Column(length=20, nullable=false)
public DocumentTypes type;
@Constraints.Required
@Formats.NonEmpty
@Column(nullable=false)
public String document;
}
tôi phù hợp với enum sử dụng này trong bộ điều khiển của tôi:
DynamicForm form = form().bindFromRequest();
// ...
Document doc = new Document();
doc.type = DocumentTypes.valueOf(form.field("type").value());
doc.save();
Vấn đề là trong cơ sở dữ liệu, nó được lưu trữ dưới dạng "tài liệu Microsoft Word", nhưng tôi muốn lưu nó dưới dạng DOC.
Tôi có thể làm như thế nào?
Cảm ơn sự giúp đỡ của bạn!
Hoàn hảo! EnumValue đã làm việc rất tốt cho tôi! Cảm ơn :) –
Cả hai liên kết đều đã chết, bạn có thể thêm một số mô tả về điều này không? – TheChetan