import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
/**
* 举报业务线
*/
public enum ActivityPosterTypeEnum {
ZJY(1, "自驾游"),
JCYL(2, "聚餐娱乐"),
GYHD(3, "公益活动"),
QSN(4, "青少年"),
TYJJ(5, "体育竞技"),
CYJQ(6, "车友接亲"),
NHZNQ(7, "年会/周年庆");
private Integer value;
private String name;
ActivityPosterTypeEnum(Integer value, String name) {
this.value = value;
this.name = name;
}
public Integer getValue() {
return value;
}
public String getName() {
return name;
}
public static Optional<ActivityPosterTypeEnum> valueOf(Integer value) {
for (ActivityPosterTypeEnum posterTypeEnum : values()) {
if (posterTypeEnum.getValue().equals(value)) {
return Optional.of(posterTypeEnum);
}
}
return Optional.empty();
}
public static List<PosterType> getPosterTypeList() {
//获取枚举值转list集合
//这个model是自定义的一个类 放了两个字段,一个枚举值 一个枚举名称
List<PosterType> list = new LinkedList<>();
for (ActivityPosterTypeEnum posterTypeEnum : values()) {
PosterType posterType = new PosterType();
posterType.setId(posterTypeEnum.getValue());
posterType.setName(posterTypeEnum.getName());
list.add(posterType);
}
return list;
}
/**
* 对象
*/
public static class PosterType {
public int id;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String name;
}
public static void main(String[] args) {
//转json数据输出
System.out.println(Z.safeToJSON(getPosterTypeList()));
}
}
输出结果:
因为是静态方法 直接用就可以了:
ActivityPosterTypeEnum.getPosterTypeList()