我正在使用JasperReports。在那使用表和java bean数据源。但是,当我将数据从我的 java 类发送到 jrxml 表时,它会少显示一条记录。例如,如果我们在我的 java 类中有四条记录,但是当将其导出为报告时,它只显示三条记录。数据Bean如下: public class DataBean implements Serializable {
private static final long serialVersionUID = 1L;
private String description;
private String location;
private Date date;
private String type;
private String state;
private String comments;
/**
* Parameterized constructor.
*
* @param description
* description of alarm.
* @param location
* location of alarm.
* @param date
* date of alarm.
* @param type
* type of alarm.
* @param state
* state of alarm.
* @param note
* note/comments of alarm.
*/
public DataBean(String description, String location, Date date,
String type, String state, String note) {
this.description = description;
this.location = location;
this.date = date;
this.type = type;
this.state = state;
this.comments = note;
}
/**
* Getter method to get the
*
* @return location
*/
public String getLocation() {
return location;
}
/**
* Setter method to set the location.
*
* @param location
*/
public void setLocation(String location) {
this.location = location;
}
/**
* Getter method to get the date.
*
* @return date
*/
public Date getDate() {
return date;
}
/**
* Setter method to set the date.
*
* @param date
*/
public void setDate(Date date) {
this.date = date;
}
/**
* Getter method to get the type.
*
* @return type
*/
public String getType() {
return type;
}
/**
* Setter method to set the type.
*
* @param type
*/
public void setType(String type) {
this.type = type;
}
/**
* Getter method to get the state.
*
* @return state
*/
public String getState() {
return state;
}
/**
* Setter method to set the state.
*
* @param state
*/
public void setState(String state) {
this.state = state;
}
/**
* Getter method to get the description.
*
* @return description
*/
public String getDescription() {
return description;
}
/**
* Setter method to set the description.
*
* @param description
*/
public void setDescription(String description) {
this.description = description;
}
/**
* Getter method to get the comments.
*
* @return comments
*/
public String getComments() {
return comments;
}
/**
* Setter method to set the comments.
*
* @param comments
*/
public void setComments(String comments) {
this.comments = comments;
}
}
我的主类如下: List beanCollection = new ArrayList();
for (int i = 0; i < 2; i++) {
DataBean bean = new DataBean("Alarm Description", "Location",
new Date(), "EventScheduleStopped-12", "AlarmAcknowledged",
"This is the test note for the alarm.");
beanCollection.add(bean);
}
System.out.println(beanCollection.size());
List<FilterBean> filterCollection = new ArrayList<FilterBean>();
FilterBean filterBean = new FilterBean("Last 7 Days", "Any Type",
"Open");
filterCollection.add(filterBean);
InputStream inputStream = ReportManagementController.class
.getResourceAsStream("/report.jrxml");
JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(
beanCollection);
JRBeanCollectionDataSource filterBeanCollectionDataSource = new JRBeanCollectionDataSource(
filterCollection);
Map parameters = new HashMap();
parameters.put(SHOW_COMMENTS, true);
parameters.put(SHOW_FILTERS, false);
parameters.put("logo",
ReportManagementController.class.getResource(NEW_IMAGE_NAME)
.getPath());
parameters.put("TableDataSource", beanColDataSource);
parameters.put("filterDataSource", filterBeanCollectionDataSource);
JasperDesign jasperDesign = JRXmlLoader.load(inputStream);
JasperReport jasperReport = JasperCompileManager
.compileReport(jasperDesign);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,
parameters, beanColDataSource);
JasperViewer.viewReport(jasperPrint);
我的jrxml(只显示jrxml的部分内容,因为它太大了)如下:
参数名称="TableDataSource" 类="net.sf.jasperreports.engine.JRDataSource"/
dataSourceExpression>![CDATA[$P{TableDataSource}]]>dataSourceExpression> 请有人帮帮我。