[英]Using a POJO as an iReport data source
I have a POJO that compiles data from various sources into a single object. 我有一个POJO,可将来自各种来源的数据编译为一个对象。 The object is instantiated with a single parameter.
该对象用单个参数实例化。 Example:
例:
Invoice inv=new Invoice(1239);
This will bring back a complete invoice containing other POJOs populated with data from various sources (such as the billing and shipping addresses as Address
objects). 这将带回完整的发票,其中包含其他POJO,这些POJO填充有来自各种来源的数据(例如,作为
Address
对象的账单和收货地址)。
Can I use this as a data source within iReport? 我可以将其用作iReport中的数据源吗?
You could try use a JRMapCollectionDataSource
from which you can build a DataSource from a collection. 您可以尝试使用
JRMapCollectionDataSource
,从中可以从集合构建数据源。
You could take the values from the POJO object and place them into a collection if possible. 您可以从POJO对象中获取值,并尽可能将它们放入集合中。
Here is some sample code for constructing a DataSource. 这是一些用于构造数据源的示例代码。
Collection<Map<String, Object>> myColl = new ArrayList<Map<String,Object>>();
Map<String, Object> map1 = new HashMap<String, Object>();
map1.put("Field1","Value1");
map1.put("Field2","Value2");
map1.put("Field3", someObject);
myColl.add(map1);
JRMapCollectionDataSource source = new JRMapCollectionDataSource(myColl);
Another option would be to create a custom datasource by implementing JRRewindableDataSource
or JRDataSource
. 另一种选择是通过实现
JRRewindableDataSource
或JRDataSource
来创建自定义数据源。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.