调解系统后端服务

EnumsInterface.java 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. package com.ruoyi.common.interfaces;
  2. import java.lang.reflect.Method;
  3. /**
  4. * 枚举接口,反射出枚举code对应的文本 或 文本对应的code
  5. *
  6. * @Author wangqiong
  7. * @Date 2023/01/5
  8. * @Version V1.0
  9. */
  10. public interface EnumsInterface {
  11. static <T extends EnumsInterface>String getText(Class<T> clazz, String code){
  12. try {
  13. Method method = clazz.getMethod("getTextByCode", String.class);
  14. if(method!=null){
  15. return (String)method.invoke(null,code);
  16. }
  17. }catch (Exception e){
  18. System.err.println("getTextByCode方法不存在");
  19. e.printStackTrace();
  20. }
  21. return code;
  22. }
  23. static <T extends EnumsInterface>String getCode(Class<T> clazz,String text){
  24. try {
  25. Method method = clazz.getMethod("getCodeByText", String.class);
  26. if(method!=null){
  27. return (String)method.invoke(null,text);
  28. }
  29. }catch (Exception e){
  30. System.err.println("getCodeByText方法不存在");
  31. e.printStackTrace();
  32. }
  33. return text;
  34. }
  35. }