直接上代码
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;
}
/**
* 根据题型获取对象
* @param questionType
* @return
*/
public static QuestionType getQuestionTypeByType(Integer questionType){
for (QuestionType value : QuestionType.values()) {
if(value.getQuestionType().equals(questionType)){
return value;
}
}
throw new ServiceException("该题型不存在");
}
/**
* 根据描述获取对象
* @param questionName
* @return
*/
public static QuestionType getQuestionTypeBy(String questionName){
for (QuestionType value : QuestionType.values()) {
if(value.getQuestionName().equals(questionName)){
return value;
}
}
throw new ServiceException("该题型不存在");
}
/**
* 获取全部题型对象。用于前端下拉框回显
* @return
*/
public static List<QuestionType> getQuestionTypes(){
return Arrays.asList(QuestionType.values());
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/202826.html