我在 jasper studio 中制作了一个模板,该模板首先只有一个表格,我使用 JrBeanCollectionDataSource 使用 java 程序将数据传递到该表格,一切正常!但是当我尝试在报告中的表外添加字段时,它们保持为空,当我尝试将我的 JasperFillManager.fillReport(jasperReport,parameters,new JrEmptyDataSource()) 更改为 JasperFillManager.fillReport(jasperReport,parameters,itemsDataSource) 时,字段获取数据但现在表格不会获取任何数据并且根本不会出现 这是我的java程序
List<Invoice> listItems= new ArrayList<Invoice>();
Invoice invoice=new Invoice();
Invoice.setFromTo("HammamSousse/Kantaoui");
Invoice.setTripPrice("9.265");
listItems.add(invoice);
JRBeanCollectionDataSource itemsJRBean=new JRBeanCollectionDataSource(listItems);
Map<String,Object> parameters=new HashMap<String,Object>();
parameters.put("Parameter1",itemsJRBean);
InputStream input =new FileInputStream(new File("path\\vt.jrxml"));
JasperDesign jasperDesign= JRXmlLoader.load(input);
JasperReport jasperReport=JasperCompileManager.compileReport(jasperDesign);
JasperPrint jasperPrint=JasperFillManager.fillReport(jasperReport,parameters,new JREmptyDataSource());
JasperViewer.viewReport(jasperPrint);
这是我的 jrxml 文件
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.20.0.final using JasperReports Library version 6.20.0-2bc7ab61c56f459e8176eb05c7705e145cd400ad -->
<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="vt" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="39704726-dd18-487b-ad98-129fcc839d94">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<style name="Table_TH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table_CH" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<subDataset name="Dataset2" uuid="52282a42-91df-4c9f-b013-7c06e354af7d">
<queryString>
<![CDATA[]]>
</queryString>
<field name="fromTo" class="java.lang.String"/>
<field name="tripPrice" class="java.lang.String"/>
</subDataset>
<parameter name="Parameter1" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>
<queryString>
<![CDATA[]]>
</queryString>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch"/>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="67" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="274" splitType="Stretch">
<componentElement>
<reportElement x="70" y="37" width="410" height="63" uuid="f6e0b09e-81be-47e7-a751-07cc0a469e45">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
<property name="com.jaspersoft.studio.table.style.table_header" value="Table_TH"/>
<property name="com.jaspersoft.studio.table.style.column_header" value="Table_CH"/>
<property name="com.jaspersoft.studio.table.style.detail" value="Table_TD"/>
</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="Dataset2" uuid="8b074442-09df-43e1-b7e2-bd0616ee1ce8">
<dataSourceExpression><![CDATA[$P{Parameter1}]]></dataSourceExpression>
</datasetRun>
<jr:column width="250" uuid="0e2ca4af-49fd-4103-9d22-d9f95a71ae6b">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column1"/>
<jr:columnHeader style="Table_CH" height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="250" height="30" uuid="03aa47f1-fbd2-46a8-8cd3-9a353ae46704"/>
<text><![CDATA[Static Text]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table_TD" height="30">
<textField>
<reportElement x="0" y="0" width="250" height="30" uuid="daea7ee2-0796-46f1-8520-a3aff839a4a0"/>
<textFieldExpression><![CDATA[$F{fromTo}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="160" uuid="42babb80-7040-4118-8ebb-d617e52023bd">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
<jr:columnHeader style="Table_CH" height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="160" height="30" uuid="96bf0ffe-5585-48bd-a409-1c52b391f2e4"/>
<text><![CDATA[Static Text]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table_TD" height="30">
<textField>
<reportElement x="0" y="0" width="160" height="30" uuid="caa8f50d-3a61-4cb6-b7db-5da2ec76fc5b"/>
<textFieldExpression><![CDATA[$F{tripPrice}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
我想将相同的数据传递给表外的字段和表本身,有什么解决方案吗?提前致谢