枚舉類

package com.vx.springbootexcel.common.enums;/** * @author wangbs * @date 2019/6/18  11:34 */public enum BusinessTypeEnum {    BUSINESS_TYPE_ENUM("1", "業務類型1"),    BUSINESS_TYPE2_ENUM("2", "業務類型2")  ;    private  String key;    private  String value;    BusinessTypeEnum(String key, String value) {        this.key = key;        this.value = value;    }    /**     * 經過key 獲取當前的枚舉類型     * @param key     * @return     */    public static BusinessTypeEnum getEnum(String key) {        for (BusinessTypeEnum temp : BusinessTypeEnum.values()) {            if (temp.getKey().equals(key)) {                return temp;            }        }        return null;    }    /**     * 根據key 獲取value  就避免了空指針     * @param key     * @return     */    public static String getValue(String key) {        for (BusinessTypeEnum temp : BusinessTypeEnum.values()) {            if (temp.getKey().equals(key)) {                return temp.getValue();            }        }        return null;    }    public String getKey() {        return key;    }    public String getValue() {        return value;    }}
相關文章
相關標籤/搜索