1 回答

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);
}
添加回答
舉報(bào)