第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

JasperReport串聯(lián)僅打印第一個(gè)報(bào)告

JasperReport串聯(lián)僅打印第一個(gè)報(bào)告

瀟瀟雨雨 2023-07-28 15:10:02
我正在嘗試使用 JasperReports 連接兩個(gè)報(bào)告,我有一個(gè)包含來自報(bào)告“A”和報(bào)告“B”的兩個(gè) jasperPrint 的列表。問題是它只打印第一個(gè)報(bào)告,第二頁是空的。我雖然問題出在報(bào)告“B”中,但如果我先打印報(bào)告“B”,我也會(huì)遇到同樣的問題:打印報(bào)告“B”,而應(yīng)該是報(bào)告“A”的第二頁是空的。這是我的代碼:public static InputStream generatePdfByteArrayFromJasper(List<InputStream> reportStreams, Collection dataSource, HashMap<String, Object> parameters)throws JRException {    List<JasperPrint> jasperPrints = new ArrayList<>();    JRDataSource datasource = new JRBeanCollectionDataSource(dataSource, true);    for (InputStream is : reportStreams) {        JasperPrint jasperPrint = JasperFillManager.fillReport(is, parameters, datasource);        jasperPrints.add(jasperPrint);    }    JRPdfExporter exporter = new JRPdfExporter();    ByteArrayOutputStream out = new ByteArrayOutputStream();    SimpleOutputStreamExporterOutput exporterOutput = new SimpleOutputStreamExporterOutput(out);    SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();    configuration.setCreatingBatchModeBookmarks(true);    exporter.setConfiguration(configuration);    exporter.setExporterInput(SimpleExporterInput.getInstance(jasperPrints));    exporter.setExporterOutput(exporterOutput);    exporter.exportReport();    return new ByteArrayInputStream(out.toByteArray());}有人可以幫助我嗎?謝謝!
查看完整描述

1 回答

?
Cats萌萌

TA貢獻(xiàn)1805條經(jīng)驗(yàn) 獲得超9個(gè)贊

不要對(duì)兩個(gè)報(bào)表使用相同的數(shù)據(jù)源對(duì)象。數(shù)據(jù)源被第一個(gè)報(bào)告消耗,并且不會(huì)為第二個(gè)報(bào)告留下任何記錄。


您應(yīng)該做的是為每個(gè)報(bào)告創(chuàng)建數(shù)據(jù)源實(shí)例。對(duì)參數(shù)映射執(zhí)行相同的操作是一個(gè)好主意,因?yàn)樘畛溥^程會(huì)將內(nèi)置參數(shù)填充到映射中,并且存在第一個(gè)報(bào)告設(shè)置的參數(shù)最終用于第二個(gè)報(bào)告的風(fēng)險(xiǎn)。


所以代碼看起來像這樣:


public static InputStream generatePdfByteArrayFromJasper(List<InputStream> reportStreams, Collection dataSource, HashMap<String, Object> parameters)

throws JRException {

    List<JasperPrint> jasperPrints = new ArrayList<>();

    for (InputStream is : reportStreams) {

        JRDataSource datasource = new JRBeanCollectionDataSource(dataSource, true);

        HashMap<String, Object> reportParameters = new HashMap<>(parameters);

        JasperPrint jasperPrint = JasperFillManager.fillReport(is, reportParameters, datasource);

        jasperPrints.add(jasperPrint);

    }


查看完整回答
反對(duì) 回復(fù) 2023-07-28
  • 1 回答
  • 0 關(guān)注
  • 157 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)