[英]How to fill jasper report using criteria.uniqueResult();?
I want to view report by using customerId
.我想使用
customerId
查看报告。
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, ?, ?);// How to fill?
I tried:我试过了:
BLManager.java
public void report(int custId) throws JRException, FileNotFoundException {
Session session = sessionFactory.openSession();
Criteria criteria = session.createCriteria(Customer.class);
criteria.add(Restrictions.eq("custId", custId));
Customre customer = (Customer) criteria.uniqueResult();
FileInputStream fis = new FileInputStream("src/com/customer/reports/report.jrxml");
BufferedInputStream bis = new BufferedInputStream(fis);
JasperReport jasperReport = (JasperReport) JasperCompileManager.compileReport(bis);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, ?, ?);// How to fill?
JasperViewer.viewReport(jasperPrint, false);
}
Further I calling this method on buttonClick
此外,我在
buttonClick
上调用此方法Client Class
@FXML
private void viewReport(ActionEvent e) {
Customer customer = customerTable.getSelectionModel().getSelectedItem();
if (customer != null) {
int custId = customer.getCustId();
try {
bLManager.report(custId);
} catch (FileNotFoundException | JRException ex) {
Logger.getLogger(FollowUpController.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
When you use fillReport
method of JasperFillManager
, you can pass a parameterMap
.当您使用
JasperFillManager
的fillReport
方法时,您可以传递一个parameterMap
。
A parameterMap
is a HashMap
where you put as key the name of paramter managed by the report, and as value the object instance. parameterMap
映射是HashMap
,您将报告管理的参数名称作为键,并将 object 实例作为值。
This is my code to fill parameterMap
(you can use as example for your case):这是我填充
parameterMap
的代码(您可以将其用作您的案例的示例):
Map<String, Object> parameterMap = new HashMap<String, Object>;
parameterMap.put("datasource", jRdataSource);
parameterMap.put("MyComplexObject", myComplexObject); // you can pass a pojo
parameterMap.put("Title", "My report title");
You can see the documentation about JasperFillManager methods here您可以在此处查看有关 JasperFillManager 方法的文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.