gpt4 book ai didi

json - Jasper Report - 将 json IO 流传递给子报表

转载 作者:行者123 更新时间:2023-12-04 12:48:18 25 4
gpt4 key购买 nike

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

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

最佳答案

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

java 生成 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或者只是 String URL 的值

在 Java 中 设置您的 parameter您想传递给您的报告的 s (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一个网址的值(value)
<dataSourceExpression><![CDATA[new JsonDataSource(new URL($P{urlToDataSource}).openStream())]]></dataSourceExpression>

注意 :如果您的数据已经存在于主数据源中,您可以使用子数据集(不需要新的 JsonDataSource)。 Example of subdataset

关于json - Jasper Report - 将 json IO 流传递给子报表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34057099/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com