package com.jp.tech.applet.common.constant;
/**
* @author linfan.sun
* @date 2018/6/22 002216:36
*/
public enum IngredientsRisksEnum {
POX("1", "致痘"), CARCINOGENOUS("2", "致癌");
//防止字段值被修改,增加的字段也统一final表示常量
private final String key;
private final String value;
private IngredientsRisksEnum(String key, String value) {
this.key = key;
this.value = value;
}
//根据key获取枚举
public static IngredientsRisksEnum getEnumByKey(String key) {
if (null == key) {
return null;
}
for (IngredientsRisksEnum temp : IngredientsRisksEnum.values()) {
if (temp.getKey().equals(key)) {
return temp;
}
}
return null;
}
public String getKey() {
return key;
}
public String getValue() {
return value;
}
}
用法的话 通过key找value
IngredientsRisksEnum.getEnumByKey(jpIngredients.getRisks()).getValue()