| 1234567891011121314151617181920212223242526272829303132333435363738 |
- package com.ruoyi.common.interfaces;
-
- import java.lang.reflect.Method;
-
- /**
- * 枚举接口,反射出枚举code对应的文本 或 文本对应的code
- *
- * @Author wangqiong
- * @Date 2023/01/5
- * @Version V1.0
- */
- public interface EnumsInterface {
- static <T extends EnumsInterface>String getText(Class<T> clazz, String code){
- try {
- Method method = clazz.getMethod("getTextByCode", String.class);
- if(method!=null){
- return (String)method.invoke(null,code);
- }
- }catch (Exception e){
- System.err.println("getTextByCode方法不存在");
- e.printStackTrace();
- }
- return code;
- }
-
- static <T extends EnumsInterface>String getCode(Class<T> clazz,String text){
- try {
- Method method = clazz.getMethod("getCodeByText", String.class);
- if(method!=null){
- return (String)method.invoke(null,text);
- }
- }catch (Exception e){
- System.err.println("getCodeByText方法不存在");
- e.printStackTrace();
- }
- return text;
- }
- }
|