You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
738 B
30 lines
738 B
package com.pair.model;
|
|
|
|
|
|
public enum Grade {
|
|
// 枚举常量,初始化时传入对应的中文描述
|
|
ELEMENTARY("小学"),
|
|
MIDDLE("初中"),
|
|
HIGH("高中");
|
|
|
|
private final String chineseName;
|
|
|
|
Grade(String chineseName) {
|
|
this.chineseName = chineseName;
|
|
}
|
|
|
|
public String getChineseName() {
|
|
return chineseName;
|
|
}
|
|
|
|
public static Grade valueOfChinese(String chineseName) {
|
|
// 遍历所有枚举常量,匹配中文描述
|
|
for (Grade grade : Grade.values()) {
|
|
if (grade.chineseName.equals(chineseName)) {
|
|
return grade;
|
|
}
|
|
}
|
|
throw new IllegalArgumentException("不存在对应的年级:" + chineseName);
|
|
}
|
|
}
|