public static enum AmisChartType { @JsonProperty("line") LINE("line", "折線圖"), @JsonProperty("bar") BAR("bar", "柱狀圖"), @JsonProperty("pie") PIE("pie", "餅狀圖"); private String code; private String name; AmisChartType(String code, String name) { this.code = code; this.name = name; } public String getCode() { return this.code; } public void setCode(String code) { this.code = code; } public String getName() { return this.name; } public void setName(String name) { this.name = name; } public static AmisChartType of(String code) { AmisChartType[] items = values(); for (AmisChartType item : items) { if (item.getCode().equals(code)) { return item; } } throw new RuntimeException("不合法的AmisChartType枚舉code"); } public static String getNameByCode(String code) { return of(code).getName(); } @Override public String toString(){ return this.code; } }