![](/img/trans.png)
[英]using hibernate Criteria.uniqueResult() when there are several results
[英]How to fill jasper report using criteria.uniqueResult();?
我想使用customerId
查看報告。
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, ?, ?);// How to fill?
我試過了:
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);
}
此外,我在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);
}
}
}
當您使用JasperFillManager
的fillReport
方法時,您可以傳遞一個parameterMap
。
parameterMap
映射是HashMap
,您將報告管理的參數名稱作為鍵,並將 object 實例作為值。
這是我填充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");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.