2010-03-23 27 views
2

我想用jasper report來創建使用JRDataSource的pdf文檔。實際上我有一個bean對象,該對象具有另一個bean對象和一個字符串值列表,內部bean對象有兩個字符串變量。現在我不知道如何將這些全部三個變量映射到jrxml文檔中以填充pdf文檔中的值。 任何人都可以幫助我如何解決這個問題。如果你能給我一些代碼片段。如何填充這個JRDataSource?

回答

0

代碼片段從集合數據源創建JasperPrint對象。

JasperPrint jp = new JasperPrint(); 
String reportPath = "/HD/jasper/mypath/myfile.jasper"; 

Map paramsMap = new HashMap(); //put whatever parameters you want to pass to report 

//JR data source, populate with your collection 
JRDataSource reportSource = new JRBeanCollectionDataSource(reportCollection); 

jp = JasperFillManager.fillReport(reportPath, paramsMap, reportSource); 

//Here you can use the PDF generator to make a PDF file out of the jp object. Then forward it to client 
+2

我不明白。 reportCollection在哪裏初始化? – 2013-07-23 13:29:55

+0

@StefanosKargas這是一個非常古老的問題和答案。如果您有任何問題,請發佈一個新問題。 – medopal 2013-07-24 10:01:05