Tôi muốn chuyển làm tham số cho tệp .jrxml của mình một đối tượng tùy ý trong miền của tôi, ví dụ: một Người.Làm cách nào để truyền một đối tượng tùy ý để báo cáo jasper làm tham số?
InputStream reportFile = MyPage.this.getClass().getResourceAsStream("test.jrxml");
HashMap<String, Person> parameters = new HashMap<String, Person>();
parameters.put("person", new Person("John", "Doe"));
...
JasperReport report = JasperCompileManager.compileReport(reportFile);
JasperPrint print = JasperFillManager.fillReport(report, parameters, new JREmptyDataSource());
return JasperExportManager.exportReportToPdf(print);
Và trên .jrxml làm điều gì đó như:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="test" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<parameter name="PERSON" isForPrompting="false" class="myApp.domain.person"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="20">
<staticText>
<reportElement x="180" y="0" width="200" height="20"/>
<text><![CDATA[$P{PERSON.lastName}]]></text>
</staticText>
</band>
</title>
...
là một cái gì đó như thể này? Tôi có thể tìm thấy các hướng dẫn phức tạp hơn cho thấy nhiều hơn là chỉ cần chuyển qua một java.lang.String?
Cảm ơn
Liên kết bị hỏng. –