Spring mvc 如何在单个报表中显示多个表(POJO)中的数据
我正在使用Spring3、iReport、JasperReports4.5.0生成报告。我有三张像下面这样的桌子 表名字段Spring mvc 如何在单个报表中显示多个表(POJO)中的数据,spring-mvc,jasper-reports,Spring Mvc,Jasper Reports,我正在使用Spring3、iReport、JasperReports4.5.0生成报告。我有三张像下面这样的桌子 表名字段 DNdate DNPRODNAME,PRODNQTY DNPaycost,总成本 问题是我需要在单个报告中显示日期、prodName、prodQty、成本、总成本字段。但这些都指向不同的POJO类。我在谷歌上搜索过,找到了一些解决方案,比如使用子报表。 但由于我对这些报告还不熟悉,我不知道这是否是正确的解决方案。如果可能的话,任何人都可以用任何样品为我指出正确的方向。根据我
DNdate
DNPRODNAME,PRODNQTY
DNPaycost,总成本
问题是我需要在单个报告中显示日期、prodName、prodQty、成本、总成本字段。但这些都指向不同的POJO类。我在谷歌上搜索过,找到了一些解决方案,比如使用子报表。
但由于我对这些报告还不熟悉,我不知道这是否是正确的解决方案。如果可能的话,任何人都可以用任何样品为我指出正确的方向。根据我的建议,DynamicAsper最适合您的情况。 您需要使用right和HQL,它将从相应的pojo中获得您在问题中描述的所有字段,并使用适当的联接 在执行此HQL时,您将获得列表。必须传递给DynamicAsper才能为您生成报告。它将自动从pojo字段名中获取列名 下面是同样的例子
Session session = null;
try {
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session = sessionFactory.openSession();
session.beginTransaction();
List list = session.createQuery("from Employee").list();
session.getTransaction().commit();
DynamicReport dynamicReport = new ReflectiveReportBuilder(list).build();
dynamicReport.setTitle("List of Employees");
JasperPrint jasperPrint = DynamicJasperHelper.generateJasperPrint(dynamicReport, new ClassicLayoutManager(), list);
JasperViewer.viewReport(jasperPrint);
JasperExportManager.exportReportToPdfFile(jasperPrint, "C:\\TestDynamicJasper.pdf");
resp.getWriter().write("Welcome to Show Report");
resp.getWriter().flush();
resp.getWriter().close();
} catch (JRException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ColumnBuilderException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} finally {
if(session != null)
session.close();
}
希望这对您有所帮助。:) 您计划使用什么数据源?