JasperReports中变量,参数和字段之间有什么区别? [英] What is the difference between variable, parameter and field in JasperReports?

查看:358
本文介绍了JasperReports中变量,参数和字段之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 JasperReports 的新手,一直在研究一些小样本。似乎Fields,Parameters和Variables非常常用于演示动态数据,看起来很相似。那么我可以问一下他们在 JasperReports 中的具体区别是什么吗?

I am a newbie to JasperReports, have been working on some small samples. It seems "Fields", "Parameters" and "Variables" are very commonly used to demonstrate dynamic data and looks much alike. So can I ask what's their difference specifically in JasperReports?

我猜变量是在Jasper报告中定义的并且可以动态改变。参数是从外部源(Java..etc)获取的,字段是实体(数据库模式,类实体),但我不认为我的理解是正确的。

I guess variable is something defined within a Jasper report and can dynamically change. Parameter is something taking from external source (Java..etc), field is for entities (database schema, class entity), but I don't think my understand is all right.

推荐答案

根据我对 JasperReports 的个人经验,我可以推断出你将最多使用参数和字段。参数和字段是您可以从代码中填充的内存位置或值,即生成报告时。

From my personal experience with JasperReports i can deduce that you will be using Parameters and Fields the most. Parameters and fields are memory locations or values which you can populate from your code, i.e when you generate the report.

您通常会做的是使用报表的不同设置填充参数地图或地图。如果我有摘要页面或封面页(报告中的第一个),我会使用参数:

What you would usually be doing is populating a parameter map or maps with different settings for your report. I use parameters if i have a summary page or a cover page (the very first in a report) Something like:

parameters.put("authorName", author); //where authorName is a parameter you have created in your JRXML template.

接下来,您可能正在使用一些自定义变量或者您可能正在使用JasperReports提供的变量。其中一些有用的变量是:PAGE_COUNT和PAGE_NUMBER。他们跟踪...报告页数和页码。当然,您可以拥有自定义变量。

Next, you might be using some custom "variables" or you might be using variables provided from JasperReports. Some of those useful variables are: PAGE_COUNT and PAGE_NUMBER. They keep track of... report page counts and page numbers. Of course you can have custom variables.

字段用于频繁更改数据的位置。它们与参数非常相似,但每次迭代时数据都可能会发生变化。比如,一个字段可能是一次迭代的 germanCar 对象的列表,以及下一个 japaneseCar 对象的列表。我会使用一个字段来保存可能会改变的 Car 对象列表。

Fields are used where data changes frequently. They are quite similar to parameters but with each iteration the data might change. Like, a field might be a list of germanCar objects for one iteration and a list of japaneseCar object for the next. I would use a field to hold the list of Car objects that might change.

底线是参数和字段非常相似,但字段是从 JasperReportDataSource 填充的(所以它们可以在填充该数据源时经常更改),而用于封面或自定义JR设置的参数何时生成报告本身。他们可能会很混乱。

Bottom line is parameters and fields are quite similar, but fields are populated from the JasperReportDataSource (so they can change frequently as you are populating that datasource), while parameters you would use for cover pages or custom JR settings WHILE generating the report itself. They could be quite confusing.

希望这有点帮助!

这篇关于JasperReports中变量,参数和字段之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆