我必须在jasper报告中显示几个表。列表的大小仅在运行时已知。如何实现?
示例:
标题1
Column1 Column2 Column3
Value1 Value2 Value3
标题2
Column1 Column2 Column3
Value1 Value2 Value2
要显示的数据如下: 表格的每一行都由以下类别的对象表示:
public class ReservationDTO {
private static final long serialVersionUID = 1L;
/**
* Constant representing the name of the automatic primary key field.
*/
public static final String PROP_ID = "_id";
private Long _id;
private java.util.Date startHour;
private java.util.Date endHour;
private String company;
public java.util.Date getStartHour() {
return startHour;
}
public void setStartHour(java.util.Date startHour) {
this.startHour = startHour;
}
public Date getEndHour() {
return endHour;
}
public void setEndHour(Date endHour) {
this.endHour = endHour;
}
public String getCompany() {
return company;
}
public void setCompany(String company) {
this.company = company;
}
}
表的标题是从类中检索的:
import java.util.Set;
public class RoomReservationDTO {
private static final long serialVersionUID = 1L;
/**
* Constant representing the name of the automatic primary key field.
*/
Set<ReservationDTO> reservations;
String roomName;
public Set<ReservationDTO> getReservations() {
return reservations;
}
public void setReservations(Set<ReservationDTO> reservations) {
this.reservations = reservations;
}
public String getRoomName() {
return roomName;
}
public void setRoomName(String roomName) {
this.roomName = roomName;
}
}
该报告是通过以下方法创建的,其中ReservationList是一个列表
private static JasperPrint createReport( Collection<?> reservationList, String templatePath )
{
JasperPrint jasperPrint = null;
File report = new File( templatePath );
Map<String, Object> params = new HashMap<>( );
try
{
jasperPrint = JasperFillManager.fillReport( report.getAbsolutePath( ), params, new JRBeanCollectionDataSource( reservationList ) );
}
catch( JRException e )
{
}
return jasperPrint;
}