Как заполнить отчет яшмы с помощью crit.uniqueResult () ;? - PullRequest
0 голосов
/ 11 октября 2019

Я хочу просмотреть отчет, используя 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);
        }
    }
}

1 Ответ

1 голос
/ 15 октября 2019

Когда вы используете fillReport метод JasperFillManager, вы можете передать parameterMap.

A parameterMap - HashMap, где вы задаете в качестве ключа имя параметра, управляемогоотчет, а в качестве значения экземпляр объекта.

Это мой код для заполнения 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 здесь

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...