当前位置: 首页 > 知识库问答 >
问题:

Jaspersoft Studio:如何在数据适配器中使用Java bean集合

谯嘉懿
2023-03-14

文档已经过时,没有任何帮助。我使用对话框添加类和静态方法,以及保存相关类的。jar文件的路径。

当我点击测试连接时,我得到一个错误,说它找不到类....

是的,jar文件就在那个路径上。我是否需要在项目属性的其他地方或其他地方进一步研究该路径??

这里有一个链接,指向描述这个过程的文档部分

共有1个答案

卫乐童
2023-03-14

我想你的问题是全称类--可能你的箱子里的包裹不见了。

下面是它在Jaspersoft Studio 6.2.1(JSS)中工作的示例。

Bean顺序:

package ru.alex;

public class Order {

    private double price;
    private int quantity;
    private Product product;

    public double getPrice() {
        return this.price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public int getQuantity() {
        return this.quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    public Product getProduct() {
        return this.product;
    }

    public void setProduct(Product product) {
        this.product = product;
    }

    public Order(double price, int quantity, Product product) {
        this.price = price;
        this.quantity = quantity;
        this.product = product;
    }
}
package ru.alex;

public class Product {

    private String name;

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Product(String name) {
        this.name = name;
    }
}
package ru.alex;

import java.util.*;

public class OrderFactory {

    public static Collection<Order> getOrders() {
        List<Order> orders = new ArrayList<>();
        orders.add(new Order(8.0, 2, new Product("apples")));
        orders.add(new Order(2.5, 10, new Product("oranges")));
        return orders;
    }
}

此数据适配器是在向导的帮助下创建的:

在JSS中,我没有将beans.jar添加到项目的Java构建路径中,而且一切(适配器)都正常工作。它可以通过按下测试按钮来检查。

使用字段说明复选框在此游戏中不起任何作用。

在Dataset和Query Dailog中,我们可以忽略类未被…找到的消息,并在设置类名后手动添加字段。

报告如下所示:

<jasperReport ...>
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="JavaBeanCollection - orders"/>
    <field name="price" class="java.lang.Double"/>

如果我们将带有bean的jar添加到IDE构建路径中,如下所示:

<?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="Report with Bean" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="JavaBeanCollection - orders"/>
    <field name="product" class="ru.alex.Product">
        <fieldDescription><![CDATA[product]]></fieldDescription>
    </field>
    <field name="quantity" class="java.lang.Integer">
        <fieldDescription><![CDATA[quantity]]></fieldDescription>
    </field>
    <field name="price" class="java.lang.Double">
        <fieldDescription><![CDATA[price]]></fieldDescription>
    </field>
    <detail>
        <band height="30" splitType="Stretch">
            <textField>
                <reportElement x="10" y="0" width="100" height="30"/>
                <textFieldExpression><![CDATA[$F{quantity}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="110" y="0" width="100" height="30"/>
                <textFieldExpression><![CDATA[$F{price}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
</jasperReport>
<field name="productName" class="java.lang.String">
    <fieldDescription><![CDATA[product.name]]></fieldDescription>
</field>

在这种情况下,模板是:

<?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="Report with Bean" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="JavaBeanCollection - orders"/>
    <field name="product" class="ru.alex.Product">
        <fieldDescription><![CDATA[product]]></fieldDescription>
    </field>
    <field name="quantity" class="java.lang.Integer">
        <fieldDescription><![CDATA[quantity]]></fieldDescription>
    </field>
    <field name="price" class="java.lang.Double">
        <fieldDescription><![CDATA[price]]></fieldDescription>
    </field>
    <field name="productName" class="java.lang.String">
        <fieldDescription><![CDATA[product.name]]></fieldDescription>
    </field>
    <detail>
        <band height="30" splitType="Stretch">
            <textField>
                <reportElement x="10" y="0" width="100" height="30"/>
                <textFieldExpression><![CDATA[$F{quantity}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="110" y="0" width="100" height="30"/>
                <textFieldExpression><![CDATA[$F{price}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="210" y="0" width="100" height="30"/>
                <textFieldExpression><![CDATA[$F{productName}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
</jasperReport>

当心!我们可以面对在试图从我的数据适配器中检索bean时为什么会出错中描述的问题?邮政。我们应该只保留一个带有Bean类的jar。例如,jar在Java构建路径。

完整的Descition在引用的帖子中。

 类似资料:
  • > 从创建的片段中更新,将新数据设置为adapter,然后调用;但没有奏效。 像其他人一样创建一个新适配器,它对他们起作用,但对我没有任何改变: 在中创建一个更新数据的方法,如下所示: 问题是gridView的布局如下所示: 然后我只是删除了并将作为父布局。

  • 试图弄清楚更新的适配器有什么问题。 在我得到一个新的产品列表后,我尝试: > 从创建的片段中更新,将新数据设置到adapter,然后调用;但没有奏效。 像其他人一样创建一个新适配器,它对他们有效,但对我没有任何改变: 在中创建一个更新数据的方法,如下所示: 然后每当我想要更新数据列表时,我就调用这个方法;但没有奏效。 检查是否可以以任何方式修改recyclerView,并且我尝试至少删除一个项目:

  • 如何使用适配器模式 横滑的滚动栏理论上应该是这个样子的: 新建一个 Swift 文件:HorizontalScroller.swift ,作为我们的横滑滚动控件, HorizontalScroller 继承自 UIView 。 打开 HorizontalScroller.swift 文件并添加如下代码: @objc protocol HorizontalScrollerDelegate { } 这

  • 我发现了一个xml配置的入站适配器示例,但我并不完全理解。配置指定REST请求设置请求方法、使用的格式等。 我认为,从Spring集成的角度来看,响应应该更加重要,因为响应实际上是为消息通道提供信息的。我说得对吗? HTTP入站适配器用作消息endpoint(实际上是消息起始点),它调用HTTP请求,例如REST服务的URL。”http://myRest/transfer/next“-向SI消息通

  • 我对Jasper Reports是新手,我能够成功地生成一个将SQL查询嵌入到jrxml文件中的报告。(我正在为eclipse使用JasperStudio插件) 但是现在我想使用我的bean类作为数据源。在开始时需要一些帮助- 需求:用户-在屏幕上的捐赠收据表单中输入值。将DonationReceive bean保存在数据库中,并使用bean值生成一个捐赠收据pdf。

  • 如何在我的项目中动态创建以轮询和检索服务器中的文件?