Java JasperReport连接仅打印第一个报告
我试图用JasperReports连接两个报告,我有一个包含来自报告a和报告B的两个jasperPrints的列表。问题是它只打印第一个报告,第二个页面是空的。我认为问题出在报告B中,但如果我先打印报告B,我也会遇到同样的问题:报告B已打印,而应为报告A的第二页为空 这是我的密码:Java JasperReport连接仅打印第一个报告,java,jasper-reports,Java,Jasper Reports,我试图用JasperReports连接两个报告,我有一个包含来自报告a和报告B的两个jasperPrints的列表。问题是它只打印第一个报告,第二个页面是空的。我认为问题出在报告B中,但如果我先打印报告B,我也会遇到同样的问题:报告B已打印,而应为报告A的第二页为空 这是我的密码: public static InputStream generatePdfByteArrayFromJasper(List<InputStream> reportStreams, Collection d
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());
}
有人能帮我吗?
谢谢 不要对两个报告使用相同的数据源对象。数据源被第一个报表占用,第二个报表将没有记录 您应该做的是为每个报表创建e数据源实例。对参数映射执行同样的操作是一个好主意,因为填充过程将内置参数填充到映射中,并且存在第一个报告设置的参数最终用于第二个报告的风险 所以代码看起来像这样:
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);
}