浏览代码

导出Excel调整targetAttr获取值方法,防止get方法不规范

RuoYi 5 年之前
父节点
当前提交
66e8b59e26

+ 3 - 4
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/poi/ExcelUtil.java

@@ -4,7 +4,6 @@ import java.io.IOException;
4 4
 import java.io.InputStream;
5 5
 import java.io.OutputStream;
6 6
 import java.lang.reflect.Field;
7
-import java.lang.reflect.Method;
8 7
 import java.math.BigDecimal;
9 8
 import java.text.DecimalFormat;
10 9
 import java.util.ArrayList;
@@ -799,9 +798,9 @@ public class ExcelUtil<T>
799 798
         if (StringUtils.isNotEmpty(name))
800 799
         {
801 800
             Class<?> clazz = o.getClass();
802
-            String methodName = "get" + name.substring(0, 1).toUpperCase() + name.substring(1);
803
-            Method method = clazz.getMethod(methodName);
804
-            o = method.invoke(o);
801
+            Field field = clazz.getDeclaredField(name);
802
+            field.setAccessible(true);
803
+            o = field.get(o);
805 804
         }
806 805
         return o;
807 806
     }