为什么报告中只显示一行?

Why only one row is showing in report?

在 MySQL workbench 中我得到 3 行:

mysql> select * from person;
+-----+------+
| ID  | NAME |
+-----+------+
| A01 | A01  |
| A02 | A02  |
| A03 | A03  |
+-----+------+
3 rows in set (0.00 sec)

但是当我使用 jrxml 并显示为 pdf 时

我只能得到一排

+-----+------+
| ID  | NAME |
+-----+------+
| A01 | A01  |
+-----+------+

这是我的 jrxml

<?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="T0113" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" >
    <queryString>
        <![CDATA[select * from person ]]>
    </queryString>
    <field name="ID" class="java.lang.String">
        <fieldDescription><![CDATA[]]></fieldDescription>
    </field>
    <field name="NAME" class="java.lang.String">
        <fieldDescription><![CDATA[]]></fieldDescription>
    </field>
    <group name="ID">
        <groupExpression><![CDATA[$F{ID}]]></groupExpression>
    </group>
    <group name="NAME">
        <groupExpression><![CDATA[$F{NAME}]]></groupExpression>
    </group>
    <title>
        <band height="79" splitType="Stretch">
            <staticText>
                <reportElement x="240" y="0" width="100" height="30" />
                <text><![CDATA[PDFPDF]]></text>
            </staticText>
        </band>
    </title>
    <columnHeader>
        <band height="61" splitType="Stretch">
            <textField>
                <reportElement x="170" y="15" width="100" height="30" />
                <textFieldExpression><![CDATA[$F{ID}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="320" y="10" width="100" height="30" />
                <textFieldExpression><![CDATA[$F{NAME}]]></textFieldExpression>
            </textField>
        </band>
    </columnHeader>
</jasperReport>

那么如何解决这个问题?

这是因为您的字段在错误的 范围内。

Column Header This section appears at the beginning of each column in the generated document.

Detail This section is repeated for each line of data supplied by the report's data source. The detail section can be made of multiple bands.

目前你有他们在 columnHeader 你需要但他们在 detail 乐队

<detail>
    <band height="61" splitType="Stretch">
        <textField>
            <reportElement x="170" y="15" width="100" height="30" />
            <textFieldExpression><![CDATA[$F{ID}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement x="320" y="10" width="100" height="30" />
            <textFieldExpression><![CDATA[$F{NAME}]]></textFieldExpression>
        </textField>
    </band>
</detail>

要了解有关不同报告部分的更多信息,请参阅 Tutorial report section and JRBand API

只需更改详细信息带中的 <![CDATA[$F{ID}]]><![CDATA[$F{NAME}]]>,而不是列标题