JasperReports:访问自定义数据源
我对 JasperReports 还很陌生,我需要从自定义数据源创建报告。为此,我使用两种方法实现了JRDataSource
接口:
public class FacultyStudentsDS implements JRDataSource {
@Override
public Object getFieldValue(JRField field) throws JRException {
...
}
@Override
public boolean next() throws JRException {
...
}
}
然后我尝试创建一个PDF文档,这样:
pdf = JasperRunManager.runReportToPdf(reportFile.getAbsolutePath(),
new HashMap(), studentsDS);
我的问题是我不知道如何访问我传递给报表的数据。我不知道在 .jrxml 文件中写什么。如何访问 .jrxml 文件中传递给报告的 studentsDS
变量?
I am quite new to JasperReports and I need to create a report from a custom data source. For this I implemented the JRDataSource
interface, with the two methods:
public class FacultyStudentsDS implements JRDataSource {
@Override
public Object getFieldValue(JRField field) throws JRException {
...
}
@Override
public boolean next() throws JRException {
...
}
}
then I try to create a PDF document, this way:
pdf = JasperRunManager.runReportToPdf(reportFile.getAbsolutePath(),
new HashMap(), studentsDS);
My problem is that I do not know how to access the data I pass to the report. I have no idea what to write in the .jrxml file. How do I access the studentsDS
variable that I pass to the report, in the .jrxml file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要有
带。然后,在该范围内,您可以使用如下所示的方法访问数据源中的字段:根据您的需要,您可能不需要创建自己的自定义数据源。通过将 Java beans 的
Collection
包装在JRBeanCollectionDataSource
您可以使用上述$F{
语法访问该集合中 Java bean 的属性。You need to have
<detail>
band. Then within that band you can access fields from the data source by using something like the following:Depending on your needs, you might not need to create your own custom data source. By wrapping a
Collection
of Java beans in aJRBeanCollectionDataSource
you can access the properties of the Java beans in that collection using the above$F{
syntax.