问题描述
我有一个POJO,可以将来自各种来源的数据编译成单个对象。该对象使用单个参数进行实例化。示例:
I have a POJO that compiles data from various sources into a single object. The object is instantiated with a single parameter. Example:
Invoice inv=new Invoice(1239);
这将带回一份完整的发票,其中包含填充了各种来源数据的其他POJO(例如结算)和送货地址为地址
对象)。
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).
我可以在iReport中将其用作数据源吗?
Can I use this as a data source within iReport?
推荐答案
您可以尝试使用 JRMapCollectionDataSource
从中构建数据源收集。
You could try use a JRMapCollectionDataSource
from which you can build a DataSource from a collection.
您可以从POJO对象中获取值,并在可能的情况下将它们放入集合中。
You could take the values from the POJO object and place them into a collection if possible.
以下是构建数据源的示例代码。
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);
另一种选择是通过实现 JRRewindableDataSource $来创建自定义数据源c $ c>或
JRDataSource
。
Another option would be to create a custom datasource by implementing JRRewindableDataSource
or JRDataSource
.
这篇关于使用POJO作为iReport数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!