iReport工具的使用(二)
用JavaBean作为数据源开发报表
1、 创建DataBean,报表数据的每一个字段将对应该DataDean对象的一个属性
package direction.shoufei.report.groupyearfee.data;
public class CenterYearFee {
private String centerId;
private String centerName;
private String queryYear;
private double summary;
private double preYearsummary;
private double preYearRate;
private double month1Fee;
private double month2Fee;
private double month3Fee;
...
public String getCenterId() {
return centerId;
}
public void setCenterId(String centerId) {
this.centerId = centerId;
}
public String getCenterName() {
return centerName;
}
public void setCenterName(String centerName) {
this.centerName = centerName;
}
public String getQueryYear() {
return queryYear;
}
public void setQueryYear(String queryYear) {
this.queryYear = queryYear;
}
public double getSummary() {
return summary;
}
public void setSummary(double summary) {
this.summary = month1Fee + month2Fee + month3Fee + month4Fee
+ month5Fee + month6Fee + month7Fee + month8Fee + month9Fee
+ month10Fee + month11Fee + month12Fee;
}
public double getPreYearsummary() {
return preYearsummary;
}
public void setPreYearsummary(double preYearsummary) {
this.preYearsummary = preYearsummary;
}
public double getPreYearRate() {
return preYearRate;
}
public void setPreYearRate(double preYearRate) {
this.preYearRate = preYearRate;
}
public double getMonth1Fee() {
return month1Fee;
}
public void setMonth1Fee(double month1Fee) {
this.month1Fee = month1Fee;
}
public double getMonth2Fee() {
return month2Fee;
}
public void setMonth2Fee(double month2Fee) {
this.month2Fee = month2Fee;
}
public double getMonth3Fee() {
return month3Fee;
}
public void setMonth3Fee(double month3Fee) {
this.month3Fee = month3Fee;
}
...
}
public class CenterYearFee {
private String centerId;
private String centerName;
private String queryYear;
private double summary;
private double preYearsummary;
private double preYearRate;
private double month1Fee;
private double month2Fee;
private double month3Fee;
...
public String getCenterId() {
return centerId;
}
public void setCenterId(String centerId) {
this.centerId = centerId;
}
public String getCenterName() {
return centerName;
}
public void setCenterName(String centerName) {
this.centerName = centerName;
}
public String getQueryYear() {
return queryYear;
}
public void setQueryYear(String queryYear) {
this.queryYear = queryYear;
}
public double getSummary() {
return summary;
}
public void setSummary(double summary) {
this.summary = month1Fee + month2Fee + month3Fee + month4Fee
+ month5Fee + month6Fee + month7Fee + month8Fee + month9Fee
+ month10Fee + month11Fee + month12Fee;
}
public double getPreYearsummary() {
return preYearsummary;
}
public void setPreYearsummary(double preYearsummary) {
this.preYearsummary = preYearsummary;
}
public double getPreYearRate() {
return preYearRate;
}
public void setPreYearRate(double preYearRate) {
this.preYearRate = preYearRate;
}
public double getMonth1Fee() {
return month1Fee;
}
public void setMonth1Fee(double month1Fee) {
this.month1Fee = month1Fee;
}
public double getMonth2Fee() {
return month2Fee;
}
public void setMonth2Fee(double month2Fee) {
this.month2Fee = month2Fee;
}
public double getMonth3Fee() {
return month3Fee;
}
public void setMonth3Fee(double month3Fee) {
this.month3Fee = month3Fee;
}
...
}
2、 设置类路径
3、 在iReport报表设计界面添加DataBean源字段
3、 用拖拽的方式将字段添加到Band(即Detail,columnHeader,columnFooter……),并且格式化报表
![](https://images.cnblogs.com/cnblogs_com/wanglang002004/%E6%B7%BB%E5%8A%A0%E5%88%B0Band.jpg)
截止这里,报表的设计已完成。
下一步需要将报表展现的数据封装成一个List<DataBean>的对象。