我想从两个表生成一个JasperReports报告。表格为emp
和desig
尊重的bean类是
@Entity
@Table(name = "desg")
public class Designation {
@Id
@Column(name="Empid")
private int eId;
@Column(name="Designation")
private String Designation;
// getters and setters
}
@Entity
@Table(name = "emp")
public class Employee {
@Id
@GeneratedValue
@Column(name="Eid")
private int eId;
@Column(name="Name")
private String name;
@Column(name="Address")
private String address;
@Column(name="Salary")
private int salary;
// getters and setters
}
只有一个表的报告工作正常。我使用Hibernate创建bean对象列表。我要求报告如下,
List<Object[]> lst= sessio.createQuery("select e.eId, e.name, d.Designation From Employee e, Designation d where e.eId=d.eId ").list();
String reportSourceFile="E:\\classes\\report4.jrxml";
JasperReport jasperReport = null;
JasperDesign jasperDesign = null;
Map parameters = new HashMap();
parameters.put("Title", "The EMP Report");
try {
jasperDesign = JRXmlLoader.load(reportSourceFile);
jasperReport = JasperCompileManager.compileReport(jasperDesign);
byte[] byteStream = JasperRunManager.runReportToPdf(jasperReport, parameters, new JRBeanCollectionDataSource(emplst)); // what to change instead of emplst
OutputStream outStream = response.getOutputStream();
response.setHeader("Content-Disposition","filename=myReport.pdf");
response.setContentType("application/pdf");
response.setContentLength(byteStream.length);
outStream.write(byteStream,0,byteStream.length);
} catch (JRException e1) {
e1.printStackTrace();
}
如果我发送emplst
它可以正常工作,但我想在报告中打印lst
。如何将lst
对象发送到 JasperReports 的报告以及如何进入iReport工具?
答案 0 :(得分:0)
在JRXML中使用导入标记
<import value="yourPackageName.Employee">
并在数据类型为java.lang.Object
的JRXML中创建参数,可以说myEmployee
是参数名称
然后将Employee Object
作为参数传递给JRXML
Map<String,Object> map=new HashMap<String,Object>();
map.put("myEmployee",yourEmployeeObject);
现在您的员工类对象出现在JRXML中,您可以从JRXML调用getter来获取对象状态(i.e attributes of Object
)
答案 1 :(得分:0)