看完这个,你就知道枚举可以怎么定义属性和方法了
public enum TBSHOP_TYPE {
TBSHOP_c0("C0-xx","xx专卖店"), TBSHOP_C1("C1-xx","xx折扣店"), TBSHOP_C2("C2-xx","xx票务店"), TBSHOP_C3("c3-xx","xx成都店"); private String typeCode; private String desc; TBSHOP_TYPE(String typeCode,String desc){ this.typeCode= typeCode; this.desc= desc; }
public String getTypeCode() { return typeCode; } public void setTypeCode(String typeCode) { this.typeCode = typeCode; } public String getDesc() { return desc; } public void setDesc(String desc) { this.desc = desc; }
public static String getCodeByName(String name) { for (TBSHOP_TYPE item : TBSHOP_TYPE.values()) { if (item.name().equals(name)) { return item.getTypeCode(); } } return ""; }
public static String getCnDescByName(String name) { for (TBSHOP_TYPE item : TBSHOP_TYPE.values()) { if (item.name().equals(name)) { return item.getDesc(); } } return ""; } }