簡體   English   中英

如何使用 criteria.uniqueResult(); 填充碧玉報告?

[英]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);
        }
    }
}

當您使用JasperFillManagerfillReport方法時,您可以傳遞一個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");

您可以在此處查看有關 JasperFillManager 方法的文檔

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM