简体   繁体   English

使用singe java bean生成jasper报告

[英]Generate jasper report using singe java bean

i have requirement to create order declaration report, i am using jasper studio to create the jasper template. 我需要创建订单声明报告,我正在使用jasper studio创建jasper模板。 in that template i have order id, customer details and his address, with these details i have to create a report. 在该模板中,我具有订单ID,客户详细信息和他的地址,利用这些详细信息,我必须创建一个报告。

i have below jasper report code 我有以下碧玉报告代码

    JasperCompileManager.compileReportToFile("src/main/resource/orderDeclarationForm.jrxml");
    JasperPrint jasperPrint = JasperFillManager.fillReport("src/main/resource/orderDeclarationForm.jasper", new HashMap<String, Object>(), new JRTableModelDataSource(getTableModelData()));
    // JasperExportManager.exportReportToPdfFile("resource/orderDeclarationForm.jrprint");
    JasperExportManager.exportReportToPdfFile(jasperPrint, "src/main/resource/orderDeclarationForm.pdf");

but instead of JRTableModelDataSource i have to pass java bean class so the jasper engine has to take the data from one single java bean, i have gone through javabean as datasource where it takes list of beans, but my requirement is only one bean which has order details. 但是我必须传递Java Bean类,而不是JRTableModelDataSource因此jasper引擎必须从一个Java Bean中获取数据,而我已经通过javabean as datasource来接收bean列表,但是我的要求是只有一个具有顺序的bean细节。 please advice me on this 请给我建议

If you only need one instance of a bean to be passed to JasperFillManager.fillReport method, then it makes sense to pass them as parameters as long as their count is feasible (in your case its only 3). 如果只需要将一个bean实例传递给JasperFillManager.fillReport方法,则只要它们的数量可行(将其传递给您) ,就可以将它们作为参数传递。

    Map<String,Object> params = new HashMap<String,Object>();
    params.put("orderId", xxx);
    params.put("customerDetails", xxx);
    params.put("address", xxx);

Afterwards, pass this params Map object: 然后,传递此params Map对象:

JasperPrint jasperPrint = JasperFillManager.fillReport("src/main/resource/orderDeclarationForm.jasper", params, new JRTableModelDataSource(getTableModelData()));

Please check this link for more info on how to read Parameters from within your .jrxml file. 请检查链接以获取有关如何从.jrxml文件中读取参数的更多信息。

Thanks. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM