电竞比分网-中国电竞赛事及体育赛事平台

分享

Java-Jasper報告空白頁

 印度阿三17 2019-10-25

我的jrxml和Java代碼如下.我正在嘗試使用一些文本和值創(chuàng)建報告.但是,將生成空白報告.我正在粘貼地圖以將報告填充為參數(shù).我必須添加4-5條靜態(tài)行,然后添加一個動態(tài)變量.我在詳細的樂隊中添加了這些東西.錯了什么

    <?xml version="1.0" encoding="UTF-8"  ?>
    <!-- Created with iReport - A designer for JasperReports -->
    <!DOCTYPE jasperReport PUBLIC "http://JasperReports//DTD Report Design//EN" "http://jasperreports./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();

解決方法:

您正在將報告數(shù)據(jù)與參數(shù)混淆.我看不到您有任何報告數(shù)據(jù),這就是為什么您得到空報告的原因.此外,您要填充一個名為“ Field”的參數(shù),而不是實際的報告數(shù)據(jù).因此,您需要在報表中創(chuàng)建一個名為“字段”的參數(shù),然后在詳細信息區(qū)域中對其進行引用,或者您需要將報表數(shù)據(jù)傳遞到報表中,例如

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

其中dataSet是一個集合,例如List<?>.在列表中,您將擁有一個對象,其中屬性之一是字段.

來源:https://www./content-1-519251.html

    本站是提供個人知識管理的網絡存儲空間,所有內容均由用戶發(fā)布,不代表本站觀點。請注意甄別內容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權內容,請點擊一鍵舉報。
    轉藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多