Using a POJO as an iReport data source

假如想象 提交于 2019-12-12 04:25:34

问题


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);

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).

Can I use this as a data source within iReport?


回答1:


You could try use a JRMapCollectionDataSource from which you can build a DataSource from a collection.

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);

Another option would be to create a custom datasource by implementing JRRewindableDataSource or JRDataSource.



来源:https://stackoverflow.com/questions/2169300/using-a-pojo-as-an-ireport-data-source

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!