iReport/JasperReports教程

		//jasperPath:jasper文件
		File jasper = new File(jasperPath);
		
		// get report template
		JasperReport jasperReport = (JasperReport) JRLoader.loadObjectFromLocation(jasper.getPath());
		
		// set file data to report template		
		//JRBeanCollectionDataSource作为示例:
		//sessionList是bean的list, bean就是Fileds的POJO
		JRBeanCollectionDataSource collectionDataSource = new JRBeanCollectionDataSource(sessionList);
		//param是Parameters的Map
		JasperPrint jp = JasperFillManager.fillReport(jasperReport, param,collectionDataSource);

		// export report
		//以PDF为例
		JRPdfExporter rtfExporter = new JRPdfExporter();
		rtfExporter.setParameter(JRExporterParameter.JASPER_PRINT, jp);
		//rtfExporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, jpList);//for batch
		//destPDF为生成PDF文件的路径+文件名,如:D:/test.pdf
		rtfExporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destPDF);
		rtfExporter.exportReport();

 

你可能感兴趣的:(bean)