您好,我使用的Aspose-word版本是23.6,在使用组件的ReportingEngine引擎来替换文档内容时,因为数据源的某个属性是List<Map<String, String>>类型,导致最终转换的时候提示java.lang.IncompatibleClassChangeError: Found interface java.util.Map, but class was expected,请问有什么办法可以避免这个报错呢?
代码如下:
@Data
@AllArgsConstructor
@NoArgsConstructor
public static class Dto {
List<Map<String, String>> mapList;
}
public void pdf(HttpServletResponse response) throws Exception {
List<Map<String, String>> mapList = new ArrayList<>();
Map<String, String> map = new HashMap<>();
map.put("key", "value")
mapList.add(map);
Dto dto = new Dto(mapList);
try (InputStream inputStream = Files.newInputStream(Paths.get("doc\\test.docx"))) {
LoadOptions opt = new LoadOptions();
opt.getLanguagePreferences().setDefaultEditingLanguage(EditingLanguage.CHINESE_PRC);
Document doc = new Document(inputStream, opt);
ReportingEngine engine = new ReportingEngine();
engine.buildReport(doc, dto, "dto");
doc.save(response.getOutputStream(), SaveFormat.DOCX);
} catch (Exception e) {
e.printStackTrace();
}
}
文档中的内容:
<<foreach [item in dto.getMapList()]>>
<<[item.get(“key”)]>>
<</foreach>>