JasperReports在没有任何dataSource的情况下在JRXML中嵌入数据
问题描述:
我想在没有任何dataSource的情况下将数据嵌入到报告模板(jrxml)中。我想在jrxml中静态写入我的数据,并显示包含此数据的表。这真的有可能吗?
I want to embed data in report template(jrxml) without any dataSource.I want to write my data staticly in jrxml,аnd display the table with this data. It is really possible?
答
你可以有一个列表变量并使用Java类将数据存储在其中。
You can have a list variable and store the data in it using Java class.
- 使用变量类列表或集合创建变量。
- 在变量表达式中输入返回名单。
如果你使用groovy同样的东西可以实现Groovy Collection。如果您想了解常规馆藏,请参阅更多内容。
If you are using groovy same thing can be achieved Groovy Collection. Here's more if you want to learn about groovy collections .
例如:
报告中有参数/变量
<parameter name="list_collect" class="java.util.List" isForPrompting="false">
<defaultValueExpression><![CDATA[(new beandatasource()).OnFlyCollection()]]> </defaultValueExpression>
</parameter>
和Java类
package beandatasource;
import java.util.ArrayList;
public class OnFlyCollection {
public ArrayList<String> ListCollect() {
ArrayList<String> arr_list = new ArrayList<String>();
arr_list.add("A");
arr_list.add("B");
arr_list.add("C");
return arr_list;
}
}