java—使用jaspersoft和spring迭代json对象中的数组

stszievb  于 2021-06-29  发布在  Java
关注(0)|答案(1)|浏览(731)

我正在将一个json从spring解析到jaspersoft,所以我做了以下工作:

JSONObject json = new JSONObject();
json.put("t", tickets);
json.put("totalAmount", df.format(totalAmount));

mapper.writeValue(jsonFile, json.toMap());
JsonDataSource source = new JsonDataSource(jsonFile);
JasperPrint print = JasperFillManager.fillReport(report, parameters, source);

这将为我创建一个json,其中包含以下信息:

{
    "t": [
        {
            "id": 5,
            "number": 666,
            "taxpayer": {
                "name": "rodrigo",
                "idAtmTaxpayer": null,
                "cuit": "20408980675",
                "email": "rodrigo.rodriguez@marandu.com.ar"
            }
        }
    ],
    "totalAmount": "195626,92"
}

所以,我的疑问是:如何在jaspersoft中显示这些信息,而不使用子报表。
如果有人能帮助我,我将非常感激。
jasper的jxrml是:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.16.0.final using JasperReports Library version 6.16.0-48579d909b7943b64690c65c71e07e0b80981928  -->
<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="paidTicketsReport.jrxml" pageWidth="612" pageHeight="1008" whenNoDataType="AllSectionsNoDetail" columnWidth="572" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isSummaryWithPageHeaderAndFooter="true" uuid="b92698d7-fb13-42ad-9def-91a4029def19">
    <parameter name="gob_logo" class="java.lang.String"/>
    <parameter name="ipa_logo" class="java.lang.String"/>
    <queryString language="JSON">
        <![CDATA[t]]>
    </queryString>
    <field name="id" class="java.lang.Long">
        <fieldDescription><![CDATA[id]]></fieldDescription>
    </field>
    <field name="number" class="java.lang.Long">
        <fieldDescription><![CDATA[number]]></fieldDescription>
    </field>
    <field name="nameTaxpayer" class="java.lang.String">
        <fieldDescription><![CDATA[taxpayer.name]]></fieldDescription>
    </field>
    <field name="idAtmTaxPayer" class="java.lang.Long">
        <fieldDescription><![CDATA[taxpayer.idAtmTaxPayer]]></fieldDescription>
    </field>
    <field name="cuitTaxpayer" class="java.lang.String">
        <fieldDescription><![CDATA[taxpayer.cuit]]></fieldDescription>
    </field>
    <field name="emailTaxpayer" class="java.lang.String">
        <fieldDescription><![CDATA[taxpayer.email]]></fieldDescription>
    </field>
    <field name="amount" class="java.lang.String">
        <fieldDescription><![CDATA[amount]]></fieldDescription>
    </field>
ojsjcaue

ojsjcaue1#

TextFields 其表达式等于您的字段,例如。 $F{idAtmTaxPayer} 在你报告的某个波段,例如细节波段。
这对我有用。显然,因为使用t作为数据的根,“totalamount”字段将不起作用。

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.14.0.final using JasperReports Library version 6.14.0-2ab0d8625be255bf609c78e1181801213e51db8f  -->
<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="jsonTest" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="14c14d57-90eb-48b3-8c1c-cf5fa89e25ab">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="jsonData"/>       
    <queryString language="json">
        <![CDATA[t]]>
    </queryString>
    <field name="id" class="java.lang.Integer">
        <property name="net.sf.jasperreports.json.field.expression" value="id"/>
        <fieldDescription><![CDATA[id]]></fieldDescription>
    </field>
    <field name="number" class="java.lang.Integer">
        <property name="net.sf.jasperreports.json.field.expression" value="number"/>
        <fieldDescription><![CDATA[number]]></fieldDescription>
    </field>
    <field name="name" class="java.lang.String">
        <property name="net.sf.jasperreports.json.field.expression" value="taxpayer.name"/>
        <fieldDescription><![CDATA[taxpayer.name]]></fieldDescription>
    </field>
    <field name="idAtmTaxpayer" class="java.lang.String">
        <property name="net.sf.jasperreports.json.field.expression" value="taxpayer.idAtmTaxpayer"/>
        <fieldDescription><![CDATA[taxpayer.idAtmTaxpayer]]></fieldDescription>
    </field>
    <field name="cuit" class="java.lang.String">
        <property name="net.sf.jasperreports.json.field.expression" value="taxpayer.cuit"/>
        <fieldDescription><![CDATA[taxpayer.cuit]]></fieldDescription>
    </field>
    <field name="email" class="java.lang.String">
        <property name="net.sf.jasperreports.json.field.expression" value="taxpayer.email"/>
        <fieldDescription><![CDATA[taxpayer.email]]></fieldDescription>
    </field>
    <columnHeader>
        <band height="30">
            <staticText>
                <reportElement x="0" y="0" width="95" height="30" uuid="dbf8388b-5025-4a17-807d-6c0a9a26d7f4">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="43fb794c-b551-4cdf-8ca2-a6e5556583e1"/>
                </reportElement>
                <text><![CDATA[id]]></text>
            </staticText>
            <staticText>
                <reportElement x="95" y="0" width="92" height="30" uuid="8a47733e-b942-4f36-9a86-607d7f2708c4">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="5b03c677-664e-46be-b72d-b0945b895ab7"/>
                </reportElement>
                <text><![CDATA[number]]></text>
            </staticText>
            <staticText>
                <reportElement x="187" y="0" width="92" height="30" uuid="c309a2e4-a787-4fef-9d57-5f67cfbe8a85">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="1069cfbe-9bb4-4f30-a540-d111361ddb46"/>
                </reportElement>
                <text><![CDATA[name]]></text>
            </staticText>
            <staticText>
                <reportElement x="279" y="0" width="92" height="30" uuid="965e14eb-cd9f-4882-a57d-cd67afe9df00">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="ffd06315-cbb2-455d-908a-cb5b465e4a5d"/>
                </reportElement>
                <text><![CDATA[idAtmTaxpayer]]></text>
            </staticText>
            <staticText>
                <reportElement x="371" y="0" width="92" height="30" uuid="8478944a-471a-464e-acb3-d8631608bb65">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="4385b16b-71dd-4ad4-ad5f-f03e18328647"/>
                </reportElement>
                <text><![CDATA[cuit]]></text>
            </staticText>
            <staticText>
                <reportElement x="463" y="0" width="92" height="30" uuid="22d39e8e-e230-4b28-86f8-06ba6aa95b0e">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="9d594517-19e9-4187-9f77-ad7a0228557e"/>
                </reportElement>
                <text><![CDATA[email]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="30" splitType="Stretch">
            <textField>
                <reportElement x="0" y="0" width="95" height="30" uuid="45e4e430-802a-45de-95cf-5f199b5c8790">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="43fb794c-b551-4cdf-8ca2-a6e5556583e1"/>
                </reportElement>
                <textFieldExpression><![CDATA[$F{id}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="95" y="0" width="92" height="30" uuid="e6e18897-08ce-4a2d-831b-429338ad5ee8">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="5b03c677-664e-46be-b72d-b0945b895ab7"/>
                </reportElement>
                <textFieldExpression><![CDATA[$F{number}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="187" y="0" width="92" height="30" uuid="2b8f4467-21a0-4bf7-9575-6fb0b0222d3e">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="1069cfbe-9bb4-4f30-a540-d111361ddb46"/>
                </reportElement>
                <textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="279" y="0" width="92" height="30" uuid="544e5c63-f8df-4a96-9391-827acd4a9c8f">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="ffd06315-cbb2-455d-908a-cb5b465e4a5d"/>
                </reportElement>
                <textFieldExpression><![CDATA[$F{idAtmTaxpayer}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="371" y="0" width="92" height="30" uuid="87cf1ef2-db55-4a16-82ec-c838aa5606b2">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="4385b16b-71dd-4ad4-ad5f-f03e18328647"/>
                </reportElement>
                <textFieldExpression><![CDATA[$F{cuit}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="463" y="0" width="92" height="30" uuid="2dc4fc4c-a687-4df0-bf4c-78bad2f76d20">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="9d594517-19e9-4187-9f77-ad7a0228557e"/>
                </reportElement>
                <textFieldExpression><![CDATA[$F{email}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
</jasperReport>

相关问题