我创建了一个带<script src="scripts/config-esnext.js"></script>
类的参数ItemData
在表格中我添加了一个数据源表达式net.sf.jasperreports.engine.data.JRBeanCollectionDataSource
。
我使用类$P{ItemData}
创建了一个字段Data
,并将其放在“表详细信息”框中。
但结果为空。我研究了如何添加datasouce对象以及示例。但我尝试应用这段代码。但是无法实现它。
我的代码:
java.lang.String
吸气\设定器
public static void main(final String[] args) {
try {
final DataList DefinitionData= new DataList();
final List<String> Data = new ArrayList<>();
Data.add("AAG");
Data.add("SNG");
DefinitionData.setData(Data);
final JRBeanCollectionDataSource items = new JRBeanCollectionDataSource(Data);
final Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("ItemData", items);
JRXML:
public class DataList {
private List<String> Data= new ArrayList<String>();
public List<String> getData() {
return Data;
}
public void setData(final List<String> Data) {
this.Data= Data;
}
生成报告:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Passing List of String" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<subDataset name="ItemDataset">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<queryString>
<![CDATA[]]>
</queryString>
<field name="Data" class="java.lang.String"/>
</subDataset>
<parameter name="ItemData" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>
<field name="Data" class="java.lang.String">
<fieldDescription><![CDATA[_THIS]]></fieldDescription>
</field>
<summary>
<band height="285" splitType="Stretch">
<componentElement>
<reportElement x="120" y="50" width="200" height="200">
</reportElement>
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
<datasetRun subDataset="ItemDataset">
<dataSourceExpression><![CDATA[$P{ItemData}]]></dataSourceExpression>
</datasetRun>
<jr:column width="190">
<jr:tableHeader height="30">
<staticText>
<reportElement x="0" y="0" width="190" height="30"/>
<text><![CDATA[List of Data]]></text>
</staticText>
</jr:tableHeader>
<jr:detailCell height="30">
<textField>
<reportElement x="0" y="0" width="190" height="30"/>
<textFieldExpression><![CDATA[$F{Data}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</summary>
</jasperReport>
答案 0 :(得分:0)
当你将列表(java List)传递给jasper时,所以在jasper中你也必须使用List
。将Data
从java.lang.String
更改为java.util.List