我想通过传递HashMap
值来生成一个碧玉报告。但是,无论何时尝试,它只会创建具有空值的空文档。
我在这里尝试了其他示例:
Initialize a HashMap Variable in iReport
Print whole HashMap by jasperreport
但是它不起作用。附言:我是Jasper的新手。
这是我的碧玉页面:
<parameter name="testMap" class="java.util.Map"/>
<queryString language="SQL">
<![CDATA[]]>
</queryString>
<field name="schoolId" class="java.lang.Integer">
<fieldDescription><![CDATA[SchoolId]]></fieldDescription>
</field>
<field name="schoolName" class="java.lang.String">
<fieldDescription><![CDATA[SchoolName]]></fieldDescription>
</field>
<field name="schoolAddress" class="java.lang.String">
<fieldDescription><![CDATA[SchoolAddress]]></fieldDescription>
</field>
<field name="pincode" class="java.lang.Integer">
<fieldDescription><![CDATA[PinCode]]></fieldDescription>
</field>
<field name="udiseSchoolCode" class="java.lang.Integer">
<fieldDescription><![CDATA[UdiseSchoolCode]]></fieldDescription>
</field>
<field name="stateName" class="java.lang.String">
<fieldDescription><![CDATA[StateName]]></fieldDescription>
</field>
<field name="districtName" class="java.lang.String">
<fieldDescription><![CDATA[DistrictName]]></fieldDescription>
</field>
<field name="blockName" class="java.lang.String">
<fieldDescription><![CDATA[blockName]]></fieldDescription>
</field>
<field name="clusterName" class="java.lang.String">
<fieldDescription><![CDATA[clusterName]]></fieldDescription>
</field>
<field name="schoolCategoryName" class="java.lang.String">
<fieldDescription><![CDATA[schoolCategoryName]]></fieldDescription>
</field>
<field name="HighestClassID" class="java.lang.Integer">
<fieldDescription><![CDATA[HighestClassID]]></fieldDescription>
</field>
<field name="LowestClassID" class="java.lang.Integer">
<fieldDescription><![CDATA[LowestClassID]]></fieldDescription>
</field>
<field name="SchoolTypeDesc" class="java.lang.String">
<fieldDescription><![CDATA[SchoolTypeDesc]]></fieldDescription>
</field>
<field name="Acad_Session_Start_Month" class="java.lang.Integer">
<fieldDescription><![CDATA[Acad_Session_Start_Month]]></fieldDescription>
</field>
<field name="managementr_name" class="java.lang.String">
<fieldDescription><![CDATA[managementr_name]]></fieldDescription>
</field>
<field name="management_subcategory_name" class="java.lang.String">
<fieldDescription><![CDATA[management_subcategory_name]]></fieldDescription>
</field>
<field name="is_cwsn" class="java.lang.String">
<fieldDescription><![CDATA[is_cwsn]]></fieldDescription>
</field>
<field name="Is_Shift_School" class="java.lang.String">
<fieldDescription><![CDATA[Is_Shift_School]]></fieldDescription>
</field>
<field name="Is_Minority_Managed" class="java.lang.String">
<fieldDescription><![CDATA[Is_Minority_Managed]]></fieldDescription>
</field>
<field name="Is_Residential_School" class="java.lang.String">
<fieldDescription><![CDATA[Is_Residential_School]]></fieldDescription>
</field>
<field name="className" class="java.lang.String">
<fieldDescription><![CDATA[className]]></fieldDescription>
</field>
<field name="sectionName" class="java.lang.String">
<fieldDescription><![CDATA[sectionName]]></fieldDescription>
</field>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="37" splitType="Stretch">
<staticText>
<reportElement x="217" y="10" width="113" height="20" forecolor="#000000" uuid="0895c50d-8d7c-4c05-9e7c-2484ced7ce90"/>
<textElement textAlignment="Left" verticalAlignment="Middle">
<font size="12" isBold="true"/>
</textElement>
<text><![CDATA[SCHOOL PROFILE ]]></text>
</staticText>
</band>
</title>
<pageHeader>
<band splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="31" splitType="Stretch">
<staticText>
<reportElement mode="Opaque" x="0" y="5" width="554" height="21" forecolor="#000000" backcolor="#A4F5FC" uuid="92604455-cad3-498b-9931-b18406162be7"/>
<box leftPadding="2">
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement textAlignment="Left" verticalAlignment="Middle">
<font size="11" isBold="true"/>
</textElement>
<text><![CDATA[Basic Information-I]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="544" splitType="Stretch">
<staticText>
<reportElement x="0" y="10" width="80" height="14" uuid="b7c7536b-5f85-4d54-821c-fd0cf51e52ee"/>
<textElement textAlignment="Justified" verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
<text><![CDATA[U-DISE Code]]></text>
</staticText>
<staticText>
<reportElement x="0" y="34" width="80" height="14" uuid="e27aa61a-2eb6-4343-8fdc-462a619be78c"/>
<textElement textAlignment="Justified" verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
<text><![CDATA[State]]></text>
</staticText>
<staticText>
<reportElement x="0" y="58" width="80" height="14" uuid="7b3f2587-32b5-4515-8203-399cf4003e9d"/>
<textElement textAlignment="Justified" verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
<text><![CDATA[District]]></text>
</staticText>
<staticText>
<reportElement x="0" y="82" width="80" height="14" uuid="41b9dab9-b861-4086-a54c-27ff4154dad1"/>
<textElement textAlignment="Justified" verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
<text><![CDATA[Cluster]]></text>
</staticText>
<textField>
<reportElement x="91" y="10" width="177" height="14" forecolor="#000000" uuid="ba6f9ec3-31ad-4070-b64a-910c5e300bf2"/>
<box leftPadding="2" rightPadding="2">
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
<textElement textAlignment="Justified" verticalAlignment="Middle">
<font size="10" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{udiseSchoolCode}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="91" y="34" width="177" height="14" forecolor="#000000" uuid="ae513519-7b27-419f-83a3-83e88c4a2b1f"/>
<box leftPadding="2" rightPadding="2">
<pen lineColor="#000000"/>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement textAlignment="Justified" verticalAlignment="Middle">
<font size="10" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{stateName}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="91" y="58" width="177" height="14" forecolor="#000000" uuid="ac2e6830-d6ff-483b-8779-d7e8c11dd00a"/>
<box leftPadding="2" rightPadding="2">
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
<textElement textAlignment="Justified" verticalAlignment="Middle">
<font size="10" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{districtName}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="91" y="82" width="177" height="14" forecolor="#000000" uuid="9eb1aa50-f06f-410c-9bdc-144999177241"/>
<box leftPadding="2" rightPadding="2">
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
<textElement textAlignment="Justified" verticalAlignment="Middle">
<font size="10" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{clusterName}]]></textFieldExpression>
</textField>
这是我的代码:
String path = resourceLoader.getResource("classpath:reports/report1.jrxml").getURI().getPath();
JasperReport jasperReport = JasperCompileManager.compileReport(path);
logger.info("************");
// Parameters for report
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("schoolName", map.get("schoolName"));
parameters.put("SchoolAddress", map.get("SchoolAddress"));
/* Convert List to JRBeanCollectionDataSource */
//JRBeanCollectionDataSource itemsJRBean = new JRBeanCollectionDataSource(parameters);
JasperPrint print = JasperFillManager.fillReport(jasperReport, parameters, new JREmptyDataSource());
谢谢