我正在使用reactjs,spring-boot,SQL和ireport生成PDF报告。这样就打印了文件。但是传递给clientInvoice.jrxml的数据为空。我该如何解决。我已经附加了spring-boot值传递(在此处称为invoiceID,它是从前端传递的)。

public ResponseEntity generateClientInvoiceByClientInvoiceId(int id) {
    try{
        File file = ResourceUtils.getFile("classpath:report/clientInvoice.jrxml");
        InputStream input = new FileInputStream(file);

        // Compile the Jasper report from .jrxml to .japser
        JasperReport jasperReport = JasperCompileManager.compileReport(input);

        // Get the parameter
        Map<String, Object> parameters = new HashMap<>();
        parameters.put("invoiceId",id);

        JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, new JREmptyDataSource());

        // Export the report to a PDF file
        JasperExportManager.exportReportToPdfFile(jasperPrint, "D://" + id + ".pdf");
        return new ResponseEntity<Object>(null, HttpStatus.OK);

    }catch (CustomException e){
        e.printStackTrace();
        CustomErrorResponse errors = new CustomErrorResponse();
        errors.setError(e.getMessage());
        return new ResponseEntity(errors, HttpStatus.SERVICE_UNAVAILABLE);
    }catch (Exception e){
        e.printStackTrace();
        CustomErrorResponse errors = new CustomErrorResponse();
        errors.setError("Error in creating client invoice ");
        return new ResponseEntity<>(errors, HttpStatus.SERVICE_UNAVAILABLE);
    }
}


只有我已经附加了我在JRXML中使用的查询。(该查询已附加到JRXML文件中)。

<queryString>
    <![CDATA[SELECT cv.`id`,cv.`client_id`,cv.`no_of_boxes` as total_boxes,cv.`sub_total`,cv.`total_weight`, cvi.`selling_price`, SUM(cvi.`weight`),sp.`selling_prawn_category_type`,cv.`shipping_address`,c.company,sc.`category_name`,count(cvi.selling_category_id) as noOfBoxes, cvi.`selling_price`*SUM(cvi.`weight`) as total_price_per_category,cv.date FROM client_invoice cv INNER JOIN client_invoice_item cvi ON cvi.`client_invoice_id` = cv.`id`INNER JOIN `selling_prawn_category_type` sp ON cvi.`selling_category_id` = sp.`id`INNER JOIN `selling_prawn_category` sc ON sc.selling_prawn_category_id = sp.idINNER JOIN `CLIENT` c ON c.id = cv.client_idWHERE cv.`id` =$P{invoiceId}  GROUP BY cvi.`selling_category_id`]]>
</queryString>


请尽快帮助我解决此问题。

最佳答案

我认为该报告为空是因为:
new JREmptyDataSource()
您可以注入DataSource并尝试如下操作:

try (Connection connection = dataSource.getConnection()){
      JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, prepareParameters(command), connection);
    }

10-07 21:06