| | |
| | | import java.lang.reflect.Method; |
| | | |
| | | /** |
| | | * 枚举类型帮助类 |
| | | * 枚举帮助类 |
| | | * @author WWW |
| | | */ |
| | | public class EnumHelper { |
| | |
| | | * @return 返回枚举值 |
| | | */ |
| | | public static <T extends Enum<T>> T getByString(Class<T> clazz, String propertyName, String value) { |
| | | String getterMethodName = GETTER_PREFIX + StringHelper.capitalize(propertyName); |
| | | String getterMethodName = GETTER_PREFIX + StringHelper.firstCharToUpperCase(propertyName); |
| | | T result = null; |
| | | try { |
| | | T[] arr = clazz.getEnumConstants(); |
| | |
| | | break; |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage()); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | |
| | | * @return 返回枚举值 |
| | | */ |
| | | public static <T extends Enum<T>> T getByInt(Class<T> clazz, String propertyName, int value) { |
| | | String getterMethodName = GETTER_PREFIX + StringHelper.capitalize(propertyName); |
| | | String getterMethodName = GETTER_PREFIX + StringHelper.firstCharToUpperCase(propertyName); |
| | | T result = null; |
| | | try { |
| | | T[] arr = clazz.getEnumConstants(); |
| | |
| | | break; |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage()); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | | return result; |
| | | } |