贾斯珀报告与列表或Pojos集合 [英] Jasper Report with List or Collection of Pojos

查看:105
本文介绍了贾斯珀报告与列表或Pojos集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是关于Jasper Reports的。

This question is about Jasper Reports.

假设我想使用 JRBeanCollectionDataSource 这样创建一个Jasper报告...

Suppose I want to create a Jasper Report using JRBeanCollectionDataSource like this ...

jasperPrint = JasperFillManager.fillReport(JRLoader.getInputStream(fileName), parameters, new JRBeanCollectionDataSource(aList));

假设我使用的PoJo具有List类型的属性。

And suppose that the PoJo I am using has a Property of type List.

如何访问


  1. 此列表中的各个项目,

  2. 如果这个项目本身就是一个Pojo访问它在Jasper Report XML
    文件中的属性。

例如在Jasper XML文件中:

For example in the Jasper XML file:

...field name="?????" class="java.lang.String" ...

感谢您的帮助...

推荐答案

如果您的数据源包含List类型的字段(更一般地说,类型为java.util.Collection),那么您可以使用用于迭代它们的表或列表或子报表组件。使用其中一个元素并设置其数据源如下:

If your data source has fields of type List (more generally, of type java.util.Collection), then you can use a Table or List or Subreport component to iterate through them. Use one of those elements and set its data source like this:

new net.sf.jasperreports.engine.data.JRMapCollectionDataSource($F{myListField})

您还可以使用静态方法添加自己的助手类来处理适当的这些字段。

You could also add your own helper class with a static method to deal with these fields appropriately.

MongoDB出现了很多。我写了一篇关于 JasperReports馆藏的文章。它使用MongoDB作为数据源...但它同样适用于您的POJO数据源。

This comes up a lot with MongoDB. I wrote an article on Collections in JasperReports. It uses MongoDB as the data source... but it would apply equally well to your POJO data source.

这篇关于贾斯珀报告与列表或Pojos集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆