|
|
|
@@ -12,6 +12,7 @@ import net.sf.jasperreports.engine.JRDataSource; |
|
|
|
import net.sf.jasperreports.engine.JREmptyDataSource; |
|
|
|
import net.sf.jasperreports.engine.JasperFillManager; |
|
|
|
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource; |
|
|
|
import net.sf.jasperreports.engine.data.JRMapCollectionDataSource; |
|
|
|
|
|
|
|
public class PdfUtils { |
|
|
|
|
|
|
|
@@ -23,8 +24,16 @@ public class PdfUtils { |
|
|
|
|
|
|
|
public static <T> JasperPrint fillReport(JasperReport report, List<T> loopList, Map<String, Object> params) |
|
|
|
throws Exception { |
|
|
|
JRDataSource dataSources = loopList.size() > 0 ? new JRBeanCollectionDataSource(loopList) |
|
|
|
: new JREmptyDataSource(); |
|
|
|
JRDataSource dataSources; |
|
|
|
if (loopList == null || loopList.isEmpty()) { |
|
|
|
dataSources = new JREmptyDataSource(); |
|
|
|
} else if (loopList.get(0) instanceof Map) { |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
List<Map<String, ?>> rows = (List<Map<String, ?>>) loopList; |
|
|
|
dataSources = new JRMapCollectionDataSource(rows); |
|
|
|
} else { |
|
|
|
dataSources = new JRBeanCollectionDataSource(loopList); |
|
|
|
} |
|
|
|
JasperPrint jasperPrint = JasperFillManager.fillReport(report, params, dataSources); |
|
|
|
return jasperPrint; |
|
|
|
} |
|
|
|
|