Jasper reports 使用自定义数据源理解Jrxml

Jasper reports 使用自定义数据源理解Jrxml,jasper-reports,Jasper Reports,我正在使用自定义数据源创建Jasper报告。 我正在使用iReport创建报告。 虽然我可以看到报告在web上的各种文章之后工作,但我无法理解生成的Jrxml如何知道它应该从自定义JRDatasource获取数据? 我在任何地方都看不到指向自定义数据源类的Jrxml 有人能提供更多的信息吗 下面是生成的Jrxml <?xml version="1.0" encoding="UTF-8"?> <jasperReport xmlns="http://jasperreports.so

我正在使用自定义数据源创建Jasper报告。 我正在使用iReport创建报告。 虽然我可以看到报告在web上的各种文章之后工作,但我无法理解生成的Jrxml如何知道它应该从自定义JRDatasource获取数据? 我在任何地方都看不到指向自定义数据源类的Jrxml

有人能提供更多的信息吗

下面是生成的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="test" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="a19f56bb-4764-4dad-8177-9a410a0cb69d">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="New Data Adapter "/>
<queryString>
    <![CDATA[]]>
</queryString>
<field name="productCode" class="java.lang.String"/>
<field name="stockLevelStatus" class="java.lang.String">
    <fieldDescription><![CDATA[stockLevelStatus]]></fieldDescription>
</field>
<background>
    <band splitType="Stretch"/>
</background>
<pageHeader>
    <band height="35" splitType="Stretch"/>
</pageHeader>
<detail>
    <band height="125" splitType="Stretch">
        <textField>
            <reportElement x="10" y="60" width="100" height="30" uuid="53ec360c-996a-48eb-9777-efbb9d5fa3d7"/>
            <textFieldExpression><![CDATA[$F{productCode}]]></textFieldExpression>
        </textField>
        <staticText>
            <reportElement x="10" y="0" width="100" height="30" uuid="dc8fcc8f-6294-4d5b-97de-4b68d2e6bb8b"/>
            <text><![CDATA[productCode]]></text>
        </staticText>
        <textField>
            <reportElement x="140" y="60" width="100" height="30" uuid="5219cffe-1786-4bd8-a8af-83eebda483cf"/>
            <textFieldExpression><![CDATA[$F{stockLevelStatus}]]></textFieldExpression>
        </textField>
        <staticText>
            <reportElement x="140" y="0" width="100" height="30" uuid="27edec96-50c6-4de0-830a-9593a0da7c17"/>
            <text><![CDATA[stockLevelStatus]]></text>
        </staticText>
    </band>
</detail>
</jasperReport>


有人可以与自定义数据源共享Jrxml吗?

经过大量的研发,我终于能够解决这个问题。 下面是“.jrxml”文件,它允许您在Jasper报表中绘制一个表,其中表的数据来自自定义数据源

您可以在web上找到很多文章来解释如何编写自定义数据源,但没有一篇文章提供如何在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="custom" language="groovy" pageWidth="595" pageHeight="420" whenNoDataType="BlankPage" columnWidth="595" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" scriptletClass="de.hybris.platform.cockpit.reports.scriptlets.DateTimeScriptlet" resourceBundle="localization/jasperreports">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<subDataset name="custome_datasource">      
    <queryString>
        <![CDATA[select 1 from DUAL]]>
    </queryString>
    <field name="productCode" class="java.lang.String"/>
    <field name="stockLevelStatus" class="java.lang.String">
        <fieldDescription><![CDATA[stockLevelStatus]]></fieldDescription>
    </field>
</subDataset>   
<queryString>
    <![CDATA[select 1 from DUAL]]>
</queryString>
<title>
    <band height="80" splitType="Stretch">
        <staticText>
            <reportElement x="10" y="0" width="500" height="30"/>
            <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font fontName="Arial" size="16" isBold="true"/>
            </textElement>
            <text><![CDATA[Stock Level Status Report]]></text>
        </staticText>
    </band>
</title>
<detail>
    <band height="340" splitType="Stretch">
         <componentElement>
            <reportElement key="table" x="0" y="0" width="555" height="238"/>
            <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="custome_datasource">
                    <dataSourceExpression><![CDATA[new my.dataproviders.StockLevelDataProvider()]]></dataSourceExpression>
                </datasetRun>
                <jr:column  width="130">
                    <jr:columnHeader height="30" rowSpan="1">                           
                        <staticText>
                            <reportElement x="0" y="0" width="92" height="25" backcolor="#99CCFF"/>
                            <textElement textAlignment="Center" verticalAlignment="Middle">
                                <font fontName="Arial" size="9" isBold="true"/>
                            </textElement>
                            <text><![CDATA[ProductCode]]></text>
                        </staticText>
                    </jr:columnHeader>
                    <jr:detailCell height="30" rowSpan="1">
                        <textField>
                            <reportElement x="0" y="10" width="90" height="20"/>
                            <textElement textAlignment="Center" verticalAlignment="Middle">
                                <font fontName="Arial" size="9" isBold="false"/>
                            </textElement>
                            <textFieldExpression class="java.lang.String"><![CDATA[$F{productCode}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
                <jr:column width="130">
                    <jr:columnHeader height="30" rowSpan="1">
                        <staticText>
                            <reportElement x="0" y="0" width="92" height="25" backcolor="#99CCFF"/>
                            <textElement textAlignment="Center" verticalAlignment="Middle">
                                <font fontName="Arial" size="9" isBold="true"/>
                            </textElement>
                            <text><![CDATA[StockLevel]]></text>
                        </staticText>
                    </jr:columnHeader>
                    <jr:detailCell  height="30" rowSpan="1">
                        <textField>
                            <reportElement x="0" y="10" width="90" height="20"/>
                            <textElement textAlignment="Center" verticalAlignment="Middle">
                                <font fontName="Arial" size="9" isBold="false"/>
                            </textElement>
                            <textFieldExpression class="java.lang.String"><![CDATA[$F{stockLevelStatus}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
            </jr:table>
        </componentElement>
    </band>
</detail>