Jasper Report - 将json IO流传递给子报告 [英] Jasper Report - Passing json IO stream to subreport

查看:510
本文介绍了Jasper Report - 将json IO流传递给子报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一份子报告的工作报告,它使用json源文件作为数据源。在这个子报表中,我将路径发送到subReportParameter中的json文件 net.sf.jasperreports.json.source

I have a working report with subreport which uses a json source file as data source. In this for subreport I send the path to the json file in subReportParameter net.sf.jasperreports.json.source

但是,如果我使用JSON IO流作为数据源而不是json源文件,如何将数据源传递给子报表?对于单个报告,JSON iostream运行良好,但无法在此处弄清楚如何使用子报告。

However, if I use JSON IO stream as data source instead of json source file, how do I pass the data source to the subreport? For a single report, JSON iostream works well but cant figure out how to use subreport here.

推荐答案

使用 json 来自 InputStream ,我将使用 url 制作和示例,因为这似乎是最可能的使用。

To use json from InputStream, I will make and example using an url, since this seem's to be the most probably use.

用于生成 JsonDataSource的 java 代码

The java code to generate the JsonDataSource

InputStream iostream = new URL("http://www.w3schools.com/website/Customers_MYSQL.php").openStream(); //Natrually this code is not need if you already have the iostrem
JsonDataSource dsSupReeport = new JsonDataSource(iostream);;

如何将其作为参数传递(让我们在一个中执行 2个示例 ),传递整个 JsonDataSource 或只传递 URL的 String

How do I pass it as parameter (lets do 2 examples in one), passing the whole JsonDataSource or just the String value of the URL

在java中设置您要传递给的参数你的报告(fillManager)

In java setup your parameters that you like to pass to your report (fillManager)

Map<String,Object> paramMap = new HashMap<String,Object>();
paramMap.put("datasource", new JsonDataSource(new URL("http://www.w3schools.com/website/Customers_MYSQL.php").openStream()));
paramMap.put("urlToDataSource", "http://www.w3schools.com/website/Customers_MYSQL.php");

报告设置正确类别的参数

<parameter name="datasource" class="net.sf.jasperreports.engine.data.JsonDataSource" isForPrompting="false"/>
<parameter name="urlToDataSource" class="java.lang.String" isForPrompting="false"/>

然后使用它们 dataSourceExpression 使用 JsonDataSource 是:

<dataSourceExpression><![CDATA[$P{datasource}]]></dataSourceExpression>

或使用网址的 String

<dataSourceExpression><![CDATA[new JsonDataSource(new URL($P{urlToDataSource}).openStream())]]></dataSourceExpression>

注意:如果您的数据已存在于主数据库中,则可以使用子数据集datasource(不需要新的JsonDataSource)。 子数据集示例

NOTE: You can use subdataset if your data is already present in main datasource (no need for new JsonDataSource). Example of subdataset

这篇关于Jasper Report - 将json IO流传递给子报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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