Java 从主报告传递参数时,JasperReports子报告不显示
我有一个主报告,其中java代码中的参数按Map对象显示。 在主报表中,包含一个子报表并尝试传递主报表参数 主报表和子报表可以单独工作,但主报表不显示子报表 Invoice.jrxml(主报告):Java 从主报告传递参数时,JasperReports子报告不显示,java,jasper-reports,subreport,Java,Jasper Reports,Subreport,我有一个主报告,其中java代码中的参数按Map对象显示。 在主报表中,包含一个子报表并尝试传递主报表参数 主报表和子报表可以单独工作,但主报表不显示子报表 Invoice.jrxml(主报告): billingVenuSubReport.xml(子报告): Java代码: Map<String,Object> reportParameters = new HashMap<>(); URL jrxmlUrl = this.getClass().getResourc
billingVenuSubReport.xml(子报告):
Java代码:
Map<String,Object> reportParameters = new HashMap<>();
URL jrxmlUrl = this.getClass().getResource("/jrxml");
String filePath= jrxmlUrl.getPath();
String imagePath= filePath+"/logo.jpg";
reportParameters.put("filePath", filePath);
reportParameters.put("imagePath", imagePath);
setCommonParameters(reportDTO, orderInvoiceDetail, reportParameters);
setBillingLocationParameter(orderInvoiceDetail, reportParameters);
String invoiceFileName = "invoice_"+orderId+"_"+orderItemId+".pdf";
JasperPrint jasperPrint = JasperFillManager.fillReport(filePath+"/Invoice.jasper", reportParameters, new JREmptyDataSource());
Path invoiceFilePath = storageService.getFilePath(FileCategoryEnum.INVOICE, orgId, invoiceFileName);
Resource resource = new UrlResource(invoiceFilePath.toUri());
if(resource.exists()) {
resource.getFile().delete();
}
OutputStream outputStream = new FileOutputStream(invoiceFilePath.toFile());
JasperExportManager.exportReportToPdfStream(jasperPrint, outputStream);
outputStream.flush();
outputStream.close();
<subreport isUsingCache="false">
<reportElement x="0" y="0" width="200" height="54" uuid="0b04fdb2-f4bb-4db2-935a-be96d92fa8db"/>
<subreportParameter name="billingAddress">
<subreportParameterExpression><![CDATA[$P{billingAddress}]]></subreportParameterExpression>
</subreportParameter>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource()]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{filePath} + "/BillingVenueSubReport.jasper"]]></subreportExpression>
</subreport>
Map reportParameters=new HashMap();
URL jrxmlUrl=this.getClass().getResource(“/jrxml”);
字符串filePath=jrmmlurl.getPath();
字符串imagePath=filePath+“/logo.jpg”;
reportParameters.put(“filePath”,filePath);
reportParameters.put(“imagePath”,imagePath);
setCommonParameters(reportDTO、orderInvoiceDetail、reportParameters);
setBillingLocationParameter(orderInvoiceDetail、reportParameters);
字符串invoiceFileName=“发票”+orderId+“\u”+orderItemId+”.pdf”;
JasperPrint JasperPrint=JasperFillManager.fillReport(filePath+“/Invoice.jasper”,reportParameters,新的JREptyDatasource());
路径invoiceFilePath=storageService.getFilePath(FileCategoryEnum.INVOICE,orgId,invoiceFileName);
Resource Resource=newurlresource(invoiceFilePath.toUri());
if(resource.exists()){
resource.getFile().delete();
}
OutputStream OutputStream=新文件OutputStream(invoiceFilePath.toFile());
jaspeexportmanager.exportReportToPdfStream(jasperPrint,outputStream);
outputStream.flush();
outputStream.close();
非常感谢您的帮助。子报表没有数据源,也不会生成任何输出(默认情况下) 你至少可以做两件事
jreportyDataSource
传递给子报表(就像Java代码中主报表的操作一样):
级别)中设置WhenNodeType=“AllSectionsNoDetail”
。这将导致子报表在没有数据的情况下打印除“详细信息”标注栏以外的所有标注栏(在您的情况下会这样做,因为您的子报表只使用标题标注栏)