枚举类

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;
}
}
原文地址:https://www.cnblogs.com/xiaowangbangzhu/p/11044409.html