gpt4 book ai didi

java - Jasper 报告空白页

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:01:26 33 4
gpt4 key购买 nike

下面是我的 jrxml 和 java 代码。我正在尝试创建包含一些文本和值的报告。但是生成空白报告。我正在传递 map 以将报告作为参数填充。我必须添加 4-5 个静态行,然后添加一个动态变量。我已经在详细的带中添加了这些东西。有什么问题

    <?xml version="1.0" encoding="UTF-8"  ?>
<!-- Created with iReport - A designer for JasperReports -->
<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<jasperReport
name="Untitled_report_2"
columnCount="1"
printOrder="Vertical"
orientation="Portrait"
pageWidth="595"
pageHeight="842"
columnWidth="535"
columnSpacing="0"
leftMargin="30"
rightMargin="30"
topMargin="20"
bottomMargin="20"
whenNoDataType="NoPages"
isTitleNewPage="false"
isSummaryNewPage="false">
<property name="ireport.scriptlethandling" value="0" />
<property name="ireport.encoding" value="UTF-8" />
<import value="java.util.*" />
<import value="net.sf.jasperreports.engine.*" />
<import value="net.sf.jasperreports.engine.data.*" />


<field name="Field" class="java.lang.String"/>

<background>
<band height="0" isSplitAllowed="true" >
</band>
</background>
<title>
<band height="50" isSplitAllowed="true" >
</band>
</title>
<pageHeader>
<band height="50" isSplitAllowed="true" >
</band>
</pageHeader>
<columnHeader>
<band height="30" isSplitAllowed="true" >
</band>
</columnHeader>
<detail>
<band height="100" isSplitAllowed="true" >
<staticText>
<reportElement
x="20"
y="10"
width="180"
height="30"
key="staticText-1"/>
<box></box>
<textElement>
<font/>
</textElement>
<text><![CDATA[4-5 lines text]]></text>
</staticText>
<textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
x="20"
y="40"
width="60"
height="20"
key="textField-1"/>
<box></box>
<textElement>
<font/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{Field}]]></textFieldExpression>
</textField>
<staticText>
<reportElement
x="20"
y="70"
width="160"
height="30"
key="staticText-2"/>
<box></box>
<textElement>
<font/>
</textElement>
<text><![CDATA[4-5 lines text]]></text>
</staticText>
</band>
</detail>
<columnFooter>
<band height="30" isSplitAllowed="true" >
</band>
</columnFooter>
<pageFooter>
<band height="50" isSplitAllowed="true" >
</band>
</pageFooter>
<lastPageFooter>
<band height="50" isSplitAllowed="true" >
</band>
</lastPageFooter>
<summary>
<band height="50" isSplitAllowed="true" >
</band>
</summary>
</jasperReport>

Java 代码:

    InputStream fileInput = getApplicationContext().getResource("/WEB-INF/reports/myjrxml.jrxml").getInputStream();
JasperReport jasperReport = JasperCompileManager.compileReport(fileInput);
HashMap map = new HashMap();
map.put("Field", "test");
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, map);
byte[] output1 = JasperExportManager.exportReportToPdf(jasperPrint);
String filename = "d:/test.pdf";
FileOutputStream fo = new FileOutputStream(filename);
fo.write(output1);
fo.close();

最佳答案

您将报告数据与参数混淆了。我没有看到您有任何报告数据,这就是您得到空报告的原因。此外,您正在填充一个名为“Field”的参数,而不是实际的报告数据。因此,您要么需要在报告中创建一个名为“Field”的参数,然后在详细信息带中引用它,要么需要将报告数据传递到报告中,例如

JRBeanCollectionDataSource data = new JRBeanCollectionDataSource(dataSet);
jasperPrint = JasperFillManager.fillReport(jasperReport, parameterMap, data);

哪里dataSet是一个集合,比如List<?> .在列表中,您将有一个对象,其中一个属性是 Field .

关于java - Jasper 报告空白页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51308608/

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