我在MySQL表中有一个列,它有一个枚举变量:“questionTypes”
我将如何为此制作实体?
For String我这样做:
@Column(name = "explanation")
private String explanation
public String getExplanation() {
return explanation;
}
public void setExplanation(String explanation) {
this.explanation = explanation;
}
我应该为枚举做什么?
答案 0 :(得分:5)
添加JPA的枚举注释(省略了getters / setters):
@Entity
class Answer {
@Column(name = "explanation")
private String explanation
@Column(name = "questionType")
@Enumerated(EnumType.STRING)
private QuestionType type
}
其中QuestionType
是常规Java枚举。