| Modifier and Type | Method and Description |
|---|---|
static <E extends Enum<?>,T> |
getEnumByPropertyValue(Class<E> enumClass,
String propertyName,
T specifiedValue)
通过
propertyName的 specifiedValue 获得枚举(equals判断,区分大小写). |
static <E extends Enum<?>,T> |
getEnumByPropertyValueIgnoreCase(Class<E> enumClass,
String propertyName,
T specifiedValue)
通过
propertyName的 specifiedValue(忽视大小写) 获得枚举(equalsIgnoreCase判断). |
public static <E extends Enum<?>,T> E getEnumByPropertyValueIgnoreCase(Class<E> enumClass, String propertyName, T specifiedValue)
propertyName的 specifiedValue(忽视大小写) 获得枚举(equalsIgnoreCase判断).
适用于这种
HttpMethodType带自定义属性的枚举类型,public enum HttpMethodType{ GET("get"), POST("post"); private String method; private HttpMethodType(String method){ this.method = method; } public String getMethod(){ return method; } }要取HttpMethodType 里面的 method属性值是 "get"的枚举(忽视大小写),调用方式:
EnumUtil.getEnumByPropertyValueIgnoreCase(HttpMethodType.class, "method", "get")- 如果你需要值区分大小写,可以调用
getEnumByPropertyValue(Class, String, Object)
E - the element typeT - the generic typeenumClass - 枚举类 比如 HttpMethodTypepropertyName - 字段名称,比如 HttpMethodType 的method,按照javabean 规范specifiedValue - 属性值 比如postpropertyName的值是 specifiedValue,那么返回nullNullPointerException - 如果 enumClass 是null,或者 propertyName 是nullIllegalArgumentException - 如果 propertyName 是blankBeanOperationException - 如果枚举值没有相关 propertyName 属性,比如 HttpMethodType 有 "method" 属性,但是没有 "method2222" 属性getEnumByPropertyValue(Class, String, Object, boolean)public static <E extends Enum<?>,T> E getEnumByPropertyValue(Class<E> enumClass, String propertyName, T specifiedValue)
propertyName的 specifiedValue 获得枚举(equals判断,区分大小写).
适用于这种
HttpMethodType带自定义属性的枚举类型,public enum HttpMethodType{ GET("get"), POST("post"); private String method; private HttpMethodType(String method){ this.method = method; } public String getMethod(){ return method; } }要取HttpMethodType 里面的 method属性值是 "get"的枚举(区分大小写),调用方式:
EnumUtil.getEnumByPropertyValue(HttpMethodType.class, "method", "get")- 如果你需要值不区分大小写,可以调用
getEnumByPropertyValueIgnoreCase(Class, String, Object)
E - the element typeT - the generic typeenumClass - 枚举类 比如 HttpMethodTypepropertyName - 字段名称,比如 HttpMethodType 的method,按照javabean 规范specifiedValue - 属性值 比如postpropertyName的值是 specifiedValue,那么返回nullNullPointerException - 如果 enumClass 是null,或者 propertyName 是nullIllegalArgumentException - 如果 propertyName 是blankBeanOperationException - 如果枚举值没有相关 propertyName 属性,比如 HttpMethodType 有 "method" 属性,但是没有 "method2222" 属性Copyright © 2008-2019 by feilong