在碧玉报告中列出深度嵌套的集合
List deeply nested set in jasper report
我的模型中有深层嵌套的字符串集,但我无法在我的 jasper 报告中列出它们。
我的模特:
Profile:
List<Project> projectList;
Project:
Skill skills;
Skill:
Set<String> programmingLanguages;
我创建报告,其中配置文件是主报告,技能是子报告,但我无法从技能子报告中的编程语言集获取数据。
我的 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="jasper-test" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="9f3515b2-a9bf-4194-ae0f-ceb8d4de1e70">
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false"/>
<field name="projectList" class="java.util.List"/>
<detail>
<band height="299" splitType="Stretch">
<subreport>
<reportElement x="-2" y="148" width="555" height="51" uuid="f081f980-ea14-4434-9282-beebf515cb6c"/>
<subreportParameter name="SUBREPORT_DIR"/>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource
($F{projectList})]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "jasper-subreport-project.jasper"]]></subreportExpression>
</subreport>
</band>
</detail>
</jasperReport>
项目子报告:
<?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="jasper-test" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="9f3515b2-a9bf-4194-ae0f-ceb8d4de1e70">
<field name="skills" class="com.company.profilelist.model.Skill"/>
<detail>
<band height="299" splitType="Stretch">
<subreport>
<reportElement x="296" y="43" width="200" height="100" uuid="1084d612-8188-4dcc-8b09-6e534e76b879"/>
<subreportParameter name="skills">
<subreportParameterExpression><![CDATA[$F{skills}]]></subreportParameterExpression>
</subreportParameter>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "jasper-subreport-skills.jasper"]]></subreportExpression>
</subreport>
</band>
</detail>
</jasperReport>
技能子报告:
<?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="jasper-test" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="9f3515b2-a9bf-4194-ae0f-ceb8d4de1e70">
<field name="programmingLanguages" class="java.util.Set">
<detail>
<band height="299" splitType="Stretch">
<textField>
<reportElement x="100" y="20" width="119" height="23" uuid="085d4a07-8dfa-4de4-b89d-6d915681fbc5"/>
<textElement>
<font size="9"/>
</textElement>
<textFieldExpression><![CDATA[$F{programmingLanguages}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
我无法访问技能子报表中的 programmingLanguage 字段是否缺少某些内容?
尝试以下步骤,
首先,在项目模型中声明skills
为List
Project:
List<Skill> skills;
然后,在项目报告
中将字段skills
的class
改为java.util.List
<field name="skills" class="java.util.List"/>
最后,在项目报告中添加技能子报告dataSourceExpression
,去掉项目报告中技能子报告的subreportParameterExpression
<subreport>
<reportElement x="296" y="43" width="200" height="100" uuid="1084d612-8188-4dcc-8b09-6e534e76b879"/>
<subreportParameter name="skills"/>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{skills})]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "jasper-subreport-skills.jasper"]]></subreportExpression>
</subreport>
您可以构建一个完全适合您的数据源的 java 对象,然后再构建一个以非嵌套形式显示所有需要的变量的对象,然后编写一个 Datamodel-MergeClass。对我来说效果很好。
我的模型中有深层嵌套的字符串集,但我无法在我的 jasper 报告中列出它们。
我的模特:
Profile:
List<Project> projectList;
Project:
Skill skills;
Skill:
Set<String> programmingLanguages;
我创建报告,其中配置文件是主报告,技能是子报告,但我无法从技能子报告中的编程语言集获取数据。
我的 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="jasper-test" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="9f3515b2-a9bf-4194-ae0f-ceb8d4de1e70">
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false"/>
<field name="projectList" class="java.util.List"/>
<detail>
<band height="299" splitType="Stretch">
<subreport>
<reportElement x="-2" y="148" width="555" height="51" uuid="f081f980-ea14-4434-9282-beebf515cb6c"/>
<subreportParameter name="SUBREPORT_DIR"/>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource
($F{projectList})]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "jasper-subreport-project.jasper"]]></subreportExpression>
</subreport>
</band>
</detail>
</jasperReport>
项目子报告:
<?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="jasper-test" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="9f3515b2-a9bf-4194-ae0f-ceb8d4de1e70">
<field name="skills" class="com.company.profilelist.model.Skill"/>
<detail>
<band height="299" splitType="Stretch">
<subreport>
<reportElement x="296" y="43" width="200" height="100" uuid="1084d612-8188-4dcc-8b09-6e534e76b879"/>
<subreportParameter name="skills">
<subreportParameterExpression><![CDATA[$F{skills}]]></subreportParameterExpression>
</subreportParameter>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "jasper-subreport-skills.jasper"]]></subreportExpression>
</subreport>
</band>
</detail>
</jasperReport>
技能子报告:
<?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="jasper-test" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="9f3515b2-a9bf-4194-ae0f-ceb8d4de1e70">
<field name="programmingLanguages" class="java.util.Set">
<detail>
<band height="299" splitType="Stretch">
<textField>
<reportElement x="100" y="20" width="119" height="23" uuid="085d4a07-8dfa-4de4-b89d-6d915681fbc5"/>
<textElement>
<font size="9"/>
</textElement>
<textFieldExpression><![CDATA[$F{programmingLanguages}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
我无法访问技能子报表中的 programmingLanguage 字段是否缺少某些内容?
尝试以下步骤,
首先,在项目模型中声明skills
为List
Project:
List<Skill> skills;
然后,在项目报告
中将字段skills
的class
改为java.util.List
<field name="skills" class="java.util.List"/>
最后,在项目报告中添加技能子报告dataSourceExpression
,去掉项目报告中技能子报告的subreportParameterExpression
<subreport>
<reportElement x="296" y="43" width="200" height="100" uuid="1084d612-8188-4dcc-8b09-6e534e76b879"/>
<subreportParameter name="skills"/>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{skills})]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "jasper-subreport-skills.jasper"]]></subreportExpression>
</subreport>
您可以构建一个完全适合您的数据源的 java 对象,然后再构建一个以非嵌套形式显示所有需要的变量的对象,然后编写一个 Datamodel-MergeClass。对我来说效果很好。