gpt4 book ai didi

java - 如何在jaspersoft报告的表中添加java bean的集合

转载 作者:行者123 更新时间:2023-11-30 03:07:17 28 4
gpt4 key购买 nike

我正在使用 jaspersoft 来制作报告。我需要在表中添加我的 java bean 字段集合,这是我使用 java bean 集合作为数据适配器获得的。我能够显示作为 java beans 获得的数据,但我没有找到将这些字段添加到 jaspersoft 报告中的表中的方法。请帮助我一直在从过去的一些数据中解决这个问题,但我仍然没有解决这个问题。下面是我正在尝试的源代码。

    <?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.2.0.final using JasperReports Library version 6.2.0 -->
<!-- 2015-12-23T15:07:03 -->
<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="javabeantest1" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="78330407-cdc3-4758-b2a3-2ddae526bed9">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="test factory3"/>
<style name="Table_TH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table_CH" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table 1_TH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table 1_CH" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table 1_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<subDataset name="javabean" uuid="adf401bd-6c3e-4316-8ff1-285d86d56c48">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="TestFactory1"/>
<queryString language="SQL">
<![CDATA[]]>
</queryString>
<field name="name" class="java.lang.String"/>
<field name="age" class="java.lang.Integer"/>
</subDataset>
<queryString>
<![CDATA[]]>
</queryString>
<field name="name" class="java.lang.String"/>
<field name="age" class="java.lang.Integer"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch"/>
</title>
<pageHeader>
<band height="87" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="33" splitType="Stretch">
<staticText>
<reportElement x="70" y="3" width="100" height="30" uuid="2c3c0b2c-ef69-423b-ba00-47bfb52dfade"/>
<text><![CDATA[name]]></text>
</staticText>
<staticText>
<reportElement x="170" y="1" width="100" height="30" uuid="8c4db8c2-212f-4427-89b7-5eaf3091a1aa"/>
<text><![CDATA[age]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="31" splitType="Stretch">
<textField>
<reportElement x="70" y="0" width="100" height="30" uuid="39fd9f41-27dd-406f-aa32-d6e930dc346a"/>
<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="170" y="0" width="100" height="30" uuid="1c916b19-cb2f-481c-8d0d-349eced5a8a2"/>
<textFieldExpression><![CDATA[$F{age}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="249" splitType="Stretch">
<componentElement>
<reportElement x="290" y="49" width="200" height="200" uuid="0d721a59-5052-42a4-bd71-b61e51308115">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
</reportElement>
<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="javabean" uuid="31830583-c665-4c8d-af3a-1a5a0aba5306">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource() ]]></dataSourceExpression>
</datasetRun>
<jr:column width="100" uuid="89affd55-2820-4860-a01c-ce794c5941a9">
<jr:tableHeader style="Table 1_TH" height="30"/>
<jr:tableFooter style="Table 1_TH" height="30"/>
<jr:columnHeader style="Table 1_CH" height="30">
<staticText>
<reportElement x="0" y="0" width="100" height="30" uuid="33b03723-89a8-4eba-b08a-e9360ecf3e08"/>
<text><![CDATA[name]]></text>
</staticText>
</jr:columnHeader>
<jr:columnFooter style="Table 1_CH" height="30"/>
<jr:detailCell style="Table 1_TD" height="30">
<textField>
<reportElement x="0" y="0" width="100" height="30" uuid="54e2604e-96f8-4e83-b506-ca2beeef5751"/>
<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="100" uuid="41fcbd02-87dc-4a72-8464-d9609e5e592a">
<jr:tableHeader style="Table 1_TH" height="30"/>
<jr:tableFooter style="Table 1_TH" height="30"/>
<jr:columnHeader style="Table 1_CH" height="30">
<staticText>
<reportElement x="0" y="0" width="100" height="30" uuid="f4078108-0c94-406e-907f-d20a0932afeb"/>
<text><![CDATA[age]]></text>
</staticText>
</jr:columnHeader>
<jr:columnFooter style="Table 1_CH" height="30"/>
<jr:detailCell style="Table 1_TD" height="30">
<textField>
<reportElement x="0" y="0" width="100" height="30" uuid="b1250d44-7bb0-445f-8c46-ab6c880872a8"/>
<textFieldExpression><![CDATA[$F{age}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</summary>
</jasperReport>

最佳答案

您的 Java bean 需要是这样的(对应于您的 subDataset 命名的 javabean)。

public class JavaBean {
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}

那么你需要一个List<JavaBean> JavaBean 的。

让我们想象一下您通过了这个 List作为填充过程中的参数(在带有键 listOfJavaBeans 的参数映射中)。

jrxml 定义参数

<parameter name="listOfJavaBeans" class="java.util.List"/> 

将其作为数据源使用传递到您的表。

<datasetRun subDataset="javabean" uuid="31830583-c665-4c8d-af3a-1a5a0aba5306">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{listOfJavaBeans})]]></dataSourceExpression>
</datasetRun>

关于java - 如何在jaspersoft报告的表中添加java bean的集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34432520/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com