How to load subreport resources with Jasper?

前端 未结 2 821
被撕碎了的回忆
被撕碎了的回忆 2020-12-03 16:08

With Jasper, I use resources to load the report. So, to load the main report, I use something like :

InputStream is = getClass().getResourceAsStream(\"/resou         


        
2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-03 16:34

    I did it this way:

    jasperDesign = JRXmlLoader.load(rootpath + "/WEB-INF/templates/Report.jrxml");
    jasperDesignSR = JRXmlLoader.load(rootpath + "/WEB-INF/templates/SubReport.jrxml");
    
    
    JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
    JasperReport jasperReportSR = JasperCompileManager.compileReport(jasperDesignSR);
    
    parameters.put("SubReportParam", jasperReportSR);
    JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, dataSource);
    

    "SubReportParam" would be a parameter of the type "JasperReport" as a SubreportExpression within your Report.

    In the .jrxml:

    
    

    I don't know if You use IReport for your Design of Reports. With a right click on your subreport you should find the SubreportExpression. parameters is a map which I pass to "fillReport"

    Good luck.

提交回复
热议问题