for (Field field : object.getClass().getDeclaredFields()) {
    try {
        AccessController.doPrivileged(PrivilegedAction() -> {
            ReflectionUtils.makeAccessible(field); // 通过反射类机制确定字段属性是否可获取,获取之后关闭可见性开关
                return null;
        });
        ExcelProperty annotation = field.getAnnatation(ExcelProperty.class);
        if (annotation.index() == firstColumnIndex) {
            fieldValue = field.get(object);
            break;
        }
    } catch (illegalAccessException e) {
        throw new ServiceException("解析数据时发生异常:" + e.getMessage());
    }
}
ReflectionUtils.makeAccessible(field); // 通过反射类机制确定字段属性是否可获取,获取之后关闭可见性开关
posted on 2024-06-23 12:15  人无名,则可专心练剑  阅读(19)  评论(0)    收藏  举报