This commit is contained in:
18792927508
2024-01-05 15:34:00 +08:00
parent 464eb8b824
commit 37a72958f1
10 changed files with 414 additions and 136 deletions
@@ -0,0 +1,38 @@
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;
}
}