gpt4 book ai didi

java - 贾斯珀报告 : List object getting merged with other object list while generating report

转载 作者:行者123 更新时间:2023-11-30 07:21:59 25 4
gpt4 key购买 nike

我对 JasperReports 的经验不多,但这是我的第二项任务,我一直遇到这个问题

下面是我的 Java bean 类 Report 和 ReportRecords,

Class Report{
private String field1;
private String field2;
private String field3;
private String field4;
List<ReportRecords> reportRecordData = new ArrayList<>();

....setters getters()....
}

Class ReportRecords{
private String column1;
private String column2;
private String column3;
private String column4;

....setters getters()....
}

我正在导出如下报告,

    List<Report> report = getReports();

JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(report);
Map<String, Object> parameters = new HashMap<String, Object>();
JasperPrint printFileName = JasperFillManager.fillReport(template, parameters, beanColDataSource);
JRTextExporter txtExporter = new JRTextExporter();

txtExporter.setParameter(JRTextExporterParameter.LINE_SEPARATOR, "\r\n");
txtExporter.setParameter(JRTextExporterParameter.PAGE_WIDTH, 110);
txtExporter.setParameter(JRTextExporterParameter.PAGE_HEIGHT, 80);
txtExporter.setParameter(JRExporterParameter.JASPER_PRINT, printFileName);
txtExporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "C:/report/report.txt");
txtExporter.setParameter(JRTextExporterParameter.CHARACTER_WIDTH,new Float(7));
txtExporter.setParameter(JRTextExporterParameter.CHARACTER_HEIGHT,new Float(13));
txtExporter.exportReport();

下面是 Jasper 代码,我删除了其他标签相关代码,仅在此处添加了必要的代码,

<subDataset name="serviceCodeData" uuid="6b6aa9cd-83d1-47b6-b475-2988e1a3a804">
<queryString>
<![CDATA[]]>
</queryString>
<field name="column1" class="java.lang.String"/>
<field name="column2" class="java.lang.String"/>
<field name="column3" class="java.lang.String"/>
<field name="column4" class="java.lang.String"/>
</subDataset>
<field name="Field1" class="java.lang.String"/>
<field name="Field2" class="java.lang.String"/>
<field name="Field3" class="java.lang.String"/>
<field name="Field4" class="java.lang.String"/>

<pageHeader>
<!-- All Field1 to Field4 labels and values -->
</pageHeader>
<columnHeader>
<!-- All column1 to column2 labels -->
</columnHeader>

And below is the list for column values

<detail>
<band height="19" splitType="Stretch">
<componentElement>
<reportElement x="-19" y="0" width="818" height="19" uuid="d08327de-369c-41b5-818a-2381d0f7def2"/>
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
<datasetRun subDataset="reportRecordData" uuid="f39ce5d6-7347-4911-b211-3c60cbd01590">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{reportRecordData})]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="19" width="818">
<textField>
<reportElement x="39" y="0" width="157" height="18" uuid="03ef5ad6-fafb-4c5d-aa41-a46b1474f9fd"/>
<textElement textAlignment="Left"/>
<textFieldExpression><![CDATA[$F{column1}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="39" y="0" width="157" height="18" uuid="03ef5ad6-fafb-4c5d-aa41-a46b1474f9fd"/>
<textElement textAlignment="Left"/>
<textFieldExpression><![CDATA[$F{column2}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="39" y="0" width="157" height="18" uuid="03ef5ad6-fafb-4c5d-aa41-a46b1474f9fd"/>
<textElement textAlignment="Left"/>
<textFieldExpression><![CDATA[$F{column3}}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="39" y="0" width="157" height="18" uuid="03ef5ad6-fafb-4c5d-aa41-a46b1474f9fd"/>
<textElement textAlignment="Left"/>
<textFieldExpression><![CDATA[$F{column4}]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
</band>
</detail>

报告应该如下生成,

enter image description here

但它生成如下,它将所有列表合并到一个报表对象,

enter image description here

请询问是否需要任何其他详细信息,请帮助我。

最佳答案

Jasper Reports的逻辑是首先生成pageHeadercolumnHeader(每页调用一次),然后迭代detail数据源上的带区。

这就是您获得当前结果的原因。 pageHeadercolumnHeader 是在您位于第一个记录时创建的,然后在数据源上调用两次详细列表带。

您应该将Report、Field1、.. Field4 移至详细信息区域,以便在迭代数据源时显示这些内容。

关于java - 贾斯珀报告 : List object getting merged with other object list while generating report,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37404199/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com