本文介绍了表工具显示一个较少/较少的数据库记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 JasperReports 。在那我使用表和java bean数据源。但是当我将数据从我的java类发送到jrxml表时,它会显示少一条记录。例如,如果我的java类中有四条记录,但在将其导出为报告时,它只显示三条记录。
数据Bean如下:
公共类DataBean实现Serializable {

  private static final long serialVersionUID = 1L; 

private String description;
私有字符串位置;
私人约会日期;
私有字符串类型;
私有字符串状态;
私人字符串评论;

/ **
*参数化构造函数。
*
* @param说明
*警报说明。
* @param location
*警报的位置。
* @param date
*报警日期。
* @param类型
*警报类型。
* @param state
*警报状态。
* @param note
*注意/警报评论。
* /
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方法获取
*
* @return location
* /
public String getLocation(){
返回位置;
}

/ **
*设置位置的Setter方法。
*
* @param location
* /
public void setLocation(String location){
this.location = location;
}

/ **
* Getter方法获取日期。
*
* @return date
* /
public Date getDate(){
return date;
}

/ **
*设置日期的Setter方法。
*
* @param date
* /
public void setDate(Date date){
this.date = date;
}

/ **
*获取类型的Getter方法。
*
* @return类型
* /
public String getType(){
return type;
}

/ **
*设置类型的Setter方法。
*
* @param类型
* /
public void setType(String type){
this.type = type;
}

/ **
*获取状态的Getter方法。
*
* @return state
* /
public String getState(){
return state;
}

/ **
*用于设置状态的Setter方法。
*
* @param state
* /
public void setState(String state){
this.state = state;
}

/ **
*获取描述的Getter方法。
*
* @return description
* /
public String getDescription(){
return description;
}

/ **
*用于设置描述的Setter方法。
*
* @param description
* /
public void setDescription(String description){
this.description = description;
}

/ **
*获取评论的Getter方法。
*
* @return comments
* /
public String getComments(){
return comments;
}

/ **
*用于设置注释的Setter方法。
*
* @param评论
* /
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,
这是警报的测试说明。);
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,
参数,beanColDataSource);

JasperViewer.viewReport(jasperPrint);

和我的jrxml(仅显示jrxml的部分内容,因为它太大)如下: / p>

参数name =TableDataSourceclass =net.sf.jasperreports.engine.JRDataSource/



dataSourceExpression >![CDATA [$ P {TableDataSource}]]> dataSourceExpression>

请有人帮帮我。

解决方案

这是JR的已知功能(或错误?)。



要解决此问题,请将集合(不是JRDataSource!)作为参数传递,并在dataSource中使用此集合表。



例如:

  parameters.put(beanCollection ,beanCollection); 
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,
参数,new JREmptyDataSource());

在jrxml中定义参数beanCollectionas java.util.Collection



并将jrxml中的表的DataSource表达式定义为

  new net.sf.jasperreports.engine.data .JRBeanCollectionDataSource($ P {beanCollection})


I'm using JasperReports. In that am using table and java bean datasource. But while I send the data from my java class to jrxml table it displays one less record. For example if we have four records in my java class but when exported it to report it is displaying only three records. Data Bean is as follows: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;
}

}

My main class is as follows: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);

and my jrxml (only displaying part content of jrxml as it is too big) is as follows:

parameter name="TableDataSource" class="net.sf.jasperreports.engine.JRDataSource"/

dataSourceExpression>![CDATA[$P{TableDataSource}]]>dataSourceExpression>Somebody help me please.

解决方案

It is known feature (or bug?) of JR.

To solve this problem pass collection (not JRDataSource!) as parameter and use this collection in dataSource for table.

For example:

parameters.put("beanCollection", beanCollection);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,
            parameters, new JREmptyDataSource());

In jrxml define parameter "beanCollection" as java.util.Collection

and define DataSource expression for table in jrxml as

new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{beanCollection})

这篇关于表工具显示一个较少/较少的数据库记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 03:32