gpt4 book ai didi

internationalization - 如何在运行时加载jasperreports resourcebundle?

转载 作者:行者123 更新时间:2023-12-04 08:20:22 24 4
gpt4 key购买 nike

jasper Reports是否可以在运行时加载ResourceBundle(对于i18n)?

我想从jrxml文件创建报告(例如c:\reports\report.jrxml)
我的标签位于(c:\messages\report.properties)的属性文件中。

我只找到了属性文件在类加载器中的示例。

谢谢

最佳答案

John Ferguson's blog提到技巧是使用自定义ResourceBundle实例覆盖REPORT_RESOURCE_BUNDLE参数。

// Compiling the report is not a necessary step; prefer using .jasper files
// that have been pre-compiled to avoid this compilation step.
//
JasperDesign jasperDesign = JasperManager.loadXmlDesign("Report.jrxml");
JasperReport jasperReport = JasperManager.compileReport(jasperDesign);

Map parameters = new HashMap();
parameters.put("REPORT_LOCALE",LocaleManager.currentLocale());
parameters.put("REPORT_RESOURCE_BUNDLE",resourceBundle);
Connection conn = DBConnectionFactory.getConnection();
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,
parameters,
conn);
resourceBundle可以来自任何地方。例如:
try(FileInputStream fis = new FileInputStream("/tmp/report.properties")) {
ResourceBundle resourceBundle = new PropertyResourceBundle(fis);

// Pass resourceBundle into the report, as shown above.
}

关于internationalization - 如何在运行时加载jasperreports resourcebundle?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15339158/

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