gpt4 book ai didi

java - 使用 jaspersoft ireport 创建 PDF 时出错

转载 作者:行者123 更新时间:2023-12-01 18:35:29 25 4
gpt4 key购买 nike

我使用reactjs、spring-boot、SQL 和ireport 来生成PDF 报告。这样文件就被打印出来了。但传递给 clientInvoice.jrxml 的数据为空。我如何解决这个问题。我已经附加了 spring-boot 值传递(这里指的是发票ID,它是从前端传递的)。

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>

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

最佳答案

我认为该报告是空的,因为:新的JREmptyDataSource()

您可以注入(inject) DataSource 并尝试如下操作:

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

关于java - 使用 jaspersoft ireport 创建 PDF 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60062511/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com