简体   繁体   English

如何在Jasper Report中使用包含另一个类的对象的类的对象作为数据源?

[英]How to use object of a class which contain object of another class as datasource in jasper report?

I have two different classes, One is Person and another one is Address. 我有两个不同的类,一个是Person,另一个是Address。 The Person class has an object of Address class as one of its property. Person类具有Address类的对象作为其属性之一。 For example 例如

class Person{
   String name;
   Address address;
}

I cannot change the structure of the class and cannot add any new collections because of other problems. 由于其他问题,我无法更改类的结构,也无法添加任何新集合。

My problem is, I want to use objects of Person class as datasource for my JasperReports 's report which has fields from both Person and Address Class. 我的问题是,我想使用Person类的对象作为JasperReports报表的数据源,该报表同时具有Person和Address Class的字段。 Can Somebody Please Help 有人可以帮忙吗

You can try something like this: 您可以尝试如下操作:

  1. Declare only the instances variables of the Person class as jasper reports fields: one field will be "name" of type java.lang.String and another field will be "address" of type your.package.Address (that's it). 仅将Person类的实例变量声明为jasper report字段:一个字段将是java.lang.String类型的“名称”,而另一个字段将是your.package.Address类型的“ address”(就是这样)。

  2. Then, if you want to print address specific information in the report, create a Text Field square where you want such info to be displayed and use the expression editor to write something like this: $F{address}.getZipCode() (assuming that Address class has such method and you want to print such info)... 然后,如果要在报告中打印特定于地址的信息,请在要显示此类信息的地方创建一个文本字段方框,然后使用表达式编辑器编写如下内容:$ F {address} .getZipCode()(假设地址类具有这种方法,并且您想打印此类信息)...

Hope this help... 希望这个帮助...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何发送清单 <Object[]> 作为碧玉报告的数据源? - How to send List<Object[]> as datasource to jasper report? 如何使用作为另一个类函数的参数访问的对象的函数? - How to use functions of an object which is accessed as a parameter to a function of another class? 在另一个 class 中使用 object - Use an object in another class Java:如何使用另一个类中的对象 - Java: how to use an object from another class 如何使用在另一个类中返回的对象 - How to use an object that got return in another class 线程类不包含以Object类为参数的构造函数 - Thread class does not contain constructor which takes Object class as parameter 有一个IDL类文件,其中包含另一个IDL类文件的对象,我想使用该内部类对象并为其分配一个字符串值 - there is an IDL class file which contains object of another IDL class file and i want to use that the inner class object and assign it a string value 调用在另一个类中创建的对象的方法 - Call a method of the object which is created in another class 如何使用Quartz Scheduler调用在浏览器上显示jasper报告的servlet类文件 - How to call a servlet class file which displays a jasper report on the browser using Quartz Scheduler 如何使用可以用不同的 class 扩展的 object 方法? - How to use a method with an object which could be extended with different class?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM