如何将任意对象作为参数传递给jasper报告?

我想作为参数传递给我的.jrxml我的域的任意对象,例如Person。

InputStream reportFile = MyPage.this.getClass().getResourceAsStream("test.jrxml"); HashMap parameters = new HashMap(); parameters.put("person", new Person("John", "Doe")); ... JasperReport report = JasperCompileManager.compileReport(reportFile); JasperPrint print = JasperFillManager.fillReport(report, parameters, new JREmptyDataSource()); return JasperExportManager.exportReportToPdf(print); 

在.jrxml上执行以下操作:

                  ... 

这样的事情可能吗? 我在哪里可以找到更复杂的教程,而不仅仅是传递java.lang.String?

谢谢

是的,您可以传递任何Java对象,但是您应该确保在JRXML中导入该对象。

在jasperReport标记内。 您可以使用标签import ,例如:

    

但是,您可以使用JRBeanCollectionDataSource并使用对象列表填充报表,而无需在params映射中存储任意对象。

有关Jasper Reports Bean Collection数据源的更多信息,请查看本教程

是的,这可能与你解释的方式完全一致。 在编译jrxml时只需确保你有正确的类路径,并注意案例 – 在所有地方都是小写( person )或大写( PERSON )。