一个对象(java bean)作为iReport(JasperReports)上的数据源 [英] One object (java bean) as data source on iReport (JasperReports)

查看:763
本文介绍了一个对象(java bean)作为iReport(JasperReports)上的数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是iReport的新手,我必须创建一个PDF报告。

I'm new in iReport and I have to create a PDF report.

使用JavaBean DataSource包装JavaBeans的数组(或集合),但我只是需要传递一个对象(只有一个JavaBean实例)。我的意思是,我必须在我的报告中显示java bean的属性。

With a JavaBean DataSource you wrap an array (or collection) of JavaBeans but I only need to pass an object (only one instance of a JavaBean). I mean, I have to show in my report the properties of a java bean.

我该怎么做?我有点困惑,我必须传递一个只有一个项目的数组?

How can I do this? I'm a little bit confused, I have to pass an array with only one item?

推荐答案

你可以将你的bean传递给报告使用 JRBeanArrayDataSource JRBeanCollectionDataSource ,或者您可以使用参数Map。

You can pass your bean to the report using a JRBeanArrayDataSource or JRBeanCollectionDataSource or you can use the parameters Map.

JasperPrint reportPrint = JasperFillManager.fillReport(
        this.getClass().getClassLoader().getResourceAsStream("/report.jasper"),
            new HashMap<String,Object>(), 
                 new JRBeanArrayDataSource(new YourBean[]{yourBean}));

Map<String,Object> params = new HashMap<String,Object>();
params.put("yourBean", yourBean);

JasperPrint reportPrint = JasperFillManager.fillReport(
        this.getClass().getClassLoader().getResourceAsStream("/report.jasper"),
                params, new JREmptyDataSource());

这篇关于一个对象(java bean)作为iReport(JasperReports)上的数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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