报告中有两个DataSource

我必须在jasperReports中做一个报告
我用这样的DataSource填充我的初始报告

File mainJasper = new File( servletContext.getRealPath("/WEB-INF/prueba.jasper") ); Map parametros = new HashMap(); parametros.put("numLista", numLista ); parametros.put("txtDestino", pas.getLista().getCiudadDestino()); parametros.put("txtFecLlegada", pas.getLista().getFecLleLista().toString()); parametros.put("txtProcedencia", pas.getLista().getCiudadProcedencia() ); parametros.put("txtNombres", con.getPersona().getNomPersona() ); parametros.put("txtFecNac", con.getPersona().getFecNacPersona().toString() ); parametros.put("txtTipoDoc", con.getPersona().getParametrica().getNomParametrica()); parametros.put("txtNroBrevete", con.getNumBrevConductor() ); parametros.put("txtOcupacion", con.getPersona().getProPersona() ); parametros.put("txtApellidos", con.getPersona().getApePatPersona() + " " +con.getPersona().getApeMatPersona() ); parametros.put("txtDomicilio", con.getPersona().getDirPersona() ); parametros.put("txtNumDoc", con.getPersona().getNumDoc() ); parametros.put("txtNacionalidad", con.getPersona().getPais().getNomPais() ); parametros.put("txtEstCivil", con.getPersona().getEstCivPersona() ); JasperReport mainReporte = (JasperReport) JRLoader.loadObject(mainJasper); JasperPrint mainPrint = JasperFillManager.fillReport(mainReporte, parametros, new JRBeanCollectionDataSource(List1)); JRExporter exporter = new JRPdfExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, mainPrint); exporter.setParameter(JRExporterParameter.OUTPUT_FILE, new java.io.File("new.pdf")); exporter.exportReport(); 

该代码工作正常,但我有另一个列表,我想在我的报告中有两个细节

我的名单是
List1实际上有效
List2是我的另一个列表
我怎么能通过这个其他名单? 我在.jxrml中也有一个子报表,但是这两个列表是不同的对象

您可以将第二个作为参数发送。

parametros.put(“dataSource2”,List2);

在报告中将参数类型设置为

net.sf.jasperreports.engine.data.JRBeanCollectionDataSource

您可以使用$ P {dataSource2}作为子报表的数据源,在表中的List中。

不确定我是否理解正确或者它是另一回事,但如果您希望这是子报表的数据源,请转到主报表上的子报表元素,添加以下行来设置它:

  ...  ...  

如果这不是您想要的,并且您需要更多具体细节,请告诉我们您将使用第二个数据源的具体内容。

一个例子 – 填充表格

1.declare一个子数据库(假设’code’和’caption’是List2中对象的字段)

         

2.实际表 – 将subDataset设置为您声明的名称(“表数据集1”)和REPORT_DATA_SOURCE参数作为包含List2(“dataSource2”)的参数

       .....