我有一個使用json源文件作爲數據源的子報表工作報告。在這裏爲子報表發送路徑到子報表json文件net.sf.jasperreports.json.source
Jasper Report - 將json IO流傳遞給子報表
但是,如果我使用JSON IO流作爲數據源而不是json源文件,我如何將數據源傳遞給子報表?對於單個報表,JSON iostream運行良好,但無法弄清楚如何在此處使用子報表。
我有一個使用json源文件作爲數據源的子報表工作報告。在這裏爲子報表發送路徑到子報表json文件net.sf.jasperreports.json.source
Jasper Report - 將json IO流傳遞給子報表
但是,如果我使用JSON IO流作爲數據源而不是json源文件,我如何將數據源傳遞給子報表?對於單個報表,JSON iostream運行良好,但無法弄清楚如何在此處使用子報表。
要使用從InputStream
json
,我會和使用URL例子,因爲這似乎對最可能使用。
的的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
(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>
或使用URL的String
值
<dataSourceExpression><![CDATA[new JsonDataSource(new URL($P{urlToDataSource}).openStream())]]></dataSourceExpression>
注意:如果您的數據已經存在於主數據源(不需要新的JsonDataSource),您可以使用子數據集。 Example of subdataset