| | |
| | | * @param dataClazz 数据对象的Class |
| | | */ |
| | | @SuppressWarnings("unchecked") |
| | | public void writeAdditionalSheet(List<?> dataList, String sheetName, Class<?> dataClazz) { if (dataList == null) { |
| | | dataList = new ArrayList<>(); |
| | | public void writeAdditionalSheet(List<?> dataList, String sheetName, Class<?> dataClazz) { |
| | | // 没有数据或没有行类型时跳过附加 Sheet: |
| | | // SatisfactionExportBundle.empty() 的 rowClass 为 null,若继续执行会把 this.clazz 置空, |
| | | // 随后 getFields() 调用 clazz.getSuperclass() 触发 NullPointerException。 |
| | | if (dataClazz == null || dataList == null || dataList.isEmpty()) { |
| | | return; |
| | | } |
| | | // 保存原始状态 |
| | | Class<T> originClazz = this.clazz; |
| | |
| | | */ |
| | | public List<Object[]> getFields() { |
| | | List<Object[]> fields = new ArrayList<Object[]>(); |
| | | // 防御:clazz 为空时不再调用 getSuperclass(),避免 NullPointerException。 |
| | | if (clazz == null) { |
| | | log.warn("ExcelUtil.clazz 为空,无法解析导出字段,跳过当前 Sheet"); |
| | | return fields; |
| | | } |
| | | List<Field> tempFields = new ArrayList<>(); |
| | | tempFields.addAll(Arrays.asList(clazz.getSuperclass().getDeclaredFields())); |
| | | tempFields.addAll(Arrays.asList(clazz.getDeclaredFields())); |