使用场景:希望根据某个key得到value以及更多信息
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
/**
* @Author NoDreamJava
* @Date 2023-7-5 10:57
* @Version 1.0
*/
@AllArgsConstructor
@NoArgsConstructor
@Getter
public enum SignOperation {
UNION("union", "union all", "合并"),
INTERSECT("intersect", "intersect", "交叉"),
EXCEPT("except", "except", "排除");
private String name;
private String val;
private String msg;
public static SignOperation getByName(String name) {
if (null != name) {
for (SignOperation item : SignOperation.values()) {
if (item.name.equals(name)) {
return item;
}
}
}
return null;
}
}
class Test{
public static void main(String[] args) {
System.out.println(SignOperation.getByName("union").getMsg());
}
}
标签:String,union,SignOperation,枚举,import,lombok,name
From: https://www.cnblogs.com/wlstudy09/p/17528022.html