我在MySQL表中有一列,该列具有一个枚举变量:“ questionTypes”

我将如何为此做实体?

对于字符串,我这样做:

@Column(name = "explanation")

private String explanation

public String getExplanation() {
  return explanation;
}

public void setExplanation(String explanation) {
  this.explanation = explanation;
}


我应该为枚举做什么?

最佳答案

添加JPA的枚举注释(省略getter / setter):

@Entity
class Answer {
   @Column(name = "explanation")
   private String explanation

   @Column(name = "questionType")
   @Enumerated(EnumType.STRING)
   private QuestionType type
}


其中QuestionType是常规Java枚举。

09-11 18:04