Pre Merge pull request !573 from 啧啧/fix/excel-util-parent-field

This commit is contained in:
啧啧 2026-06-10 03:34:11 +00:00 committed by Gitee
commit 2ba8c110ad
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -1675,9 +1675,26 @@ public class ExcelUtil<T>
if (StringUtils.isNotNull(o) && StringUtils.isNotEmpty(name))
{
Class<?> clazz = o.getClass();
Field field = clazz.getDeclaredField(name);
field.setAccessible(true);
o = field.get(o);
Field field = null;
for (; clazz != Object.class; clazz = clazz.getSuperclass())
{
try
{
field = clazz.getDeclaredField(name);
break;
}
catch (NoSuchFieldException e)
{
}
}
if (field != null)
{
field.setAccessible(true);
o = field.get(o);
} else
{
throw new NoSuchFieldException(name);
}
}
return o;
}