1

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

我将如何为此制作实体?

对于字符串,我这样做:

@Column(name = "explanation")

private String explanation

public String getExplanation() {
  return explanation;
}

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

我应该为枚举做什么?

4

1 回答 1

5

添加 JPA 的枚举注解(getters/setters 省略):

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

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

QuestionType 常规 Java 枚举在哪里。

于 2012-07-10T19:57:51.370 回答