JasperReport setParameter()已弃用? [英] JasperReport setParameter() Deprecated?

查看:259
本文介绍了JasperReport setParameter()已弃用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近为我的项目将Jasper Reports库从 3.7.6 升级到了 6.0.0 .我终于可以进行Maven构建,并且报告运行得很好.但是, setParameter()函数在两个发行版之间似乎已被弃用,并且我不确定如何重构我的代码以适应此问题.

I have recently upgraded the Jasper Reports library for my project, from 3.7.6 to 6.0.0. I can finally Maven build and the reports are working just great. However, the setParameter() function appears to have been deprecated between releases, and I am unsure how to refactor my code to accommodate for this.

private static void exportMultipleToCSV(Collection<JasperPrint> jasperPrints, OutputStream baos) throws JRException {
    JRCsvExporter csvExporter = new JRCsvExporter();

    csvExporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, jasperPrints);
    csvExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos);
    csvExporter.setParameter(JRTextExporterParameter.PAGE_HEIGHT, Integer.valueOf(1500000));
    csvExporter.setParameter(JRTextExporterParameter.PAGE_WIDTH, Integer.valueOf(40000000));
    csvExporter.setParameter(JRTextExporterParameter.CHARACTER_WIDTH, Integer.valueOf(4));
    csvExporter.setParameter(JRTextExporterParameter.CHARACTER_HEIGHT, Integer.valueOf(15));

    csvExporter.exportReport();
}

我浏览了 SourceForge 页,可以看到它已被 ExporterInput ExporterConfiguration ExporterOutput 取代,但是我不确定如何全部使用它们一起获得所需的输出.

I have looked through the SourceForge page, and can see that it has been replaced by ExporterInput, ExporterConfiguration and ExporterOutput but I am unsure how to utilise them all together to achieve the desired output.

推荐答案

等效的代码如下所示:

JRCsvExporter csvExporter = new JRCsvExporter();
//jasperPrints is Collection, but we need a List
csvExporter.setExporterInput(SimpleExporterInput.getInstance(new ArrayList(jasperPrints)));
csvExporter.setExporterOutput(new SimpleWriterExporterOutput(baos));
SimpleCsvExporterConfiguration exporterConfiguration = new SimpleCsvExporterConfiguration();
//nothing to set here, but you could do things like exporterConfiguration.setFieldDelimiter
csvExporter.setConfiguration(exporterConfiguration);
csvExporter.exportReport();

请注意,旧的API允许您执行csvExporter.setParameter(JRTextExporterParameter.PAGE_HEIGHT)之类的操作.这样做的问题是CSV导出器实际上没有使用该参数,只有文本导出器正在查看JRTextExporterParameter.PAGE_HEIGHT.使用新的API,您可以清楚地在每个导出器上执行哪些设置/配置.

Note that the old API allowed you do things like csvExporter.setParameter(JRTextExporterParameter.PAGE_HEIGHT). The problem with that was that the CSV exporter did not actually use that parameter, only the text exporter was looking at JRTextExporterParameter.PAGE_HEIGHT. With the new API, it's clear what settings/configuration you can do on each exporter.

这篇关于JasperReport setParameter()已弃用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆