[英]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: 您可以尝试如下操作:
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”(就是这样)。
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.