Jasper Report 在 Arraylist 中打印自定义对象

Jasper Report Print Custom Objects in Arraylist

我将一个列表作为参数传递给 Jasper,如下所示。

Map<String, Object> model=new HashMap<>();
  List<CustomObject> issues=new ArrayList<>();
            issues.add(new CustomObject(1,"AIRPORT Services","XYZ","asdfa","asdf","asddf"));
            issues.add(new CustomObject(1,"AIRPORT Services","XYZ","asdfa","asdf","asddf"));
            model.put("issues",issues);
            JasperPrint jasperPrint1 = JasperFillManager.fillReport(report, model, new JREmptyDataSource());

现在我可以在 jasper 中检索问题列表,但无法在 CustomObject 中检索值。

以下工作并打印使用以下迭代的 CustomObject 引用

<textFieldExpression><![CDATA[$P{list}.get($V{ROW_INDEX})]]></textFieldExpression>

当我想访问自定义对象中的字段值时会抛出异常,例如

<textFieldExpression><![CDATA[$P{list}.get($V{ROW_INDEX}).getCustomMethod()]]>

异常:

Exception obtained is: The method getCustomMethod() is undefined for the type Object value = ((java.util.List)parameter_list.getValue()).get(((java.lang.Integer)variable_ROW_INDEX.getValue())).getCustomMethod(); //$JR_EXPR_ID=0$

在 Mike Answer 的帮助下 Print an arraylist content with JasperReports 我在碧玉中迭代了我的 Arraylist。非常感谢任何帮助。

当我刚从 Object 投射到 CustomObject 时,这对我有用,就像 关注

<textFieldExpression><![CDATA[((com.custom.CustomObject)$P{flightIssues}.get($V{ROW_INDEX})).getCustomeMethod()]]></textFieldExpression>