@Data
public class DicPoi {
@Excel(name = "* 字段名称", needMerge = true)
private String name;
@Excel(name = "* 字段编码", needMerge = true)
private String code;
@Excel(name = "* 字段类型", needMerge = true)
private String type;
@Excel(name = "* 数据长度", needMerge = true)
private Long length;
@ExcelCollection(name = "关联API")
private List<DicApi> dicApiList;
@ExcelCollection(name = "关联画像")
private List<DicProfile> dicProfileList;
}
@Data
public class DicApi {
@Excel(name = "API名称")
private String name;
@Excel(name = "入参/出参")
private String paramType;
@Excel(name = "参数名称")
private String paramName;
@Excel(name = "参数code")
private String paramCode;
}
@Data
public class DicProfile {
@Excel(name = "画像名称")
private String profileName;
@Excel(name = "因子名称")
private String paramName;
@Excel(name = "因子编码")
private String paramCode;
}
public class Test {
public static void main(String[] args) {
String filePath = "/opt/导入示范模板.xlsx";
ImportParams params = new ImportParams();
params.setNeedVerfiy(true);
params.setTitleRows(1);
params.setHeadRows(2);
ExcelImportResult<DicPoi> result = ExcelImportUtil.importExcelMore(new File(filePath), DicPoi.class, params);
for (DicPoi dicPoi : result.getList()) {
System.out.println(dicPoi);
}
}
}
DicPoi(name=null, code=U0010001, type=字符型, length=8, dicApiList=[DicApi(name=身份信息查询, paramType=输出参数, paramName=姓名, paramCode=xm), DicApi(name=人员资质信息, paramType=输出参数, paramName=姓名, paramCode=name)], dicProfileList=[DicProfile(profileName=用户画像, paramName=姓名, paramCode=name), DicProfile(profileName=null, paramName=null, paramCode=null)])
可以看到关联的 name 属性读取为 null。遂打断点调试,运行至 cn.afterturn.easypoi.excel.imports.ExcelImportServer#importExcel 134行
Map<Integer, String> titlemap = this.getTitleMap(rows, params, excelCollection);
到此发现 titlemap 值不对,第一列标题被归纳到了上一级,与注解中 name 属性的列名映射不一致所以才会出现读取为 null 的情况,不知道是我的用法不对还是复杂表头映射的问题呢。