直接上代码
public enum QuestionType {
DANXUAN(0,"单选题"),
DUOXUAN(1,"多选题"),
PANDUAN(2,"判断题"),
JIESHIGAINIAN(3,"解释概念题"),
TIANKONG(4,"填空题"),
JIANDA(5,"简答题"),
HUATU(6,"画图题"),
CAILIAO(11,"材料题");
private Integer questionType;
private String questionName;
private QuestionType(Integer questionType, String questionName) {
this.questionType = questionType;
this.questionName = questionName;
}
public Integer getQuestionType() {
return questionType;
}
public String getQuestionName() {
return questionName;
}
public static QuestionType getQuestionTypeByType(Integer questionType){
for (QuestionType value : QuestionType.values()) {
if(value.getQuestionType().equals(questionType)){
return value;
}
}
throw new ServiceException("该题型不存在");
}
public static QuestionType getQuestionTypeBy(String questionName){
for (QuestionType value : QuestionType.values()) {
if(value.getQuestionName().equals(questionName)){
return value;
}
}
throw new ServiceException("该题型不存在");
}
public static List<QuestionType> getQuestionTypes(){
return Arrays.asList(QuestionType.values());
}
}