【发布时间】:2020-07-09 23:26:25
【问题描述】:
可以创建一个带有两个子报表的报表并将所有文件都放在我的数据库中吗?那么,我怎样才能通过在我的主报告中填写子报告?我需要在 Temp 文件中保存子报表,并传递目录?还是有办法在 jasperPrint 中添加子报表,然后他自动找到子报表?
这是我的代码:
try (Connection conexao = dataSource.getConnection()){
FinanceiroTransacao transacao = financeiroTransacaoService.findGatewayIdTransacaoByBoletoAndCartorio(boletoId, cns);
JasperReport jasperReport;
jasperReport = JasperCompileManager.compileReport(JRXmlLoader.load(new ByteArrayInputStream(relatorioBase.getConteudo())));
Map<String, Object> params = new HashMap<>();
params.put("pedidoId", pedidoId);
params.put("boletoId", boletoId);
params.put("cartorio",cns);
params.put("totalTransacao", transacao.getValorCredito());
params.put("idTransferencia", transacao.getGatewayPagamentoTransacaoId());
params.forEach((s, o) -> log.debug("paramentro {} , valor {}", s, o));
subReports.forEach(subReport -> {
//HERE I NEED TO add the sub reports
});
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, conexao);
JRPdfExporter pdfExporter = new JRPdfExporter();
pdfExporter.setExporterInput(new SimpleExporterInput(jasperPrint));
ByteArrayOutputStream pdfReportStream = new ByteArrayOutputStream();
pdfExporter.setExporterOutput(new SimpleOutputStreamExporterOutput(pdfReportStream));
pdfExporter.exportReport();
String retorno = Base64.getEncoder().encodeToString(pdfReportStream.toByteArray());
pdfReportStream.close();
return retorno;
}catch (Exception e){
e.printStackTrace();
throw new RuntimeException("erro: "+ e.getMessage());
}
【问题讨论】:
标签: java jasper-reports subreport