枚举类
public enum TrainingTypeEnum {
OFFLINE("offline", "线下活动"),
ONLINE("online", "线上活动");
private String value;
private String name;
TrainingTypeEnum(String value, String name) {
this.value = value;
this.name = name;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public static String getName(String value) {
for (TrainingTypeEnum ele : values()) {
if (ele.getValue().equals(value)) {
return ele.getName();
}
}
return null;
}
}
遍历
List<Map<String, String>> trainingTypeList = new ArrayList<Map<String, String>>();
Map<String, String> typeMap = null;
for (TrainingTypeEnum trainingType : TrainingTypeEnum.values()) {
typeMap = new HashMap<String, String>();
typeMap.put("value", trainingType.getValue());
typeMap.put("name", trainingType.getName());
trainingTypeList.add(typeMap);
}
model.put("trainingTypeList", trainingTypeList);