没有合适的资源?快使用搜索试试~ 我知道了~
ireport中使用javabean作数据源开发jasperreports报表

温馨提示


试读
12页
ireport中使用javabean作数据源开发jasperreports报表的详细过程 附有图片
资源推荐
资源详情
资源评论













一. 创建javabean
1.创建DailySales.java,一个简单VO bean。
package com.bjdv.catv.view;
import java.io.Serializable;
public class DailySales implements Serializable{
private static final long serialVersionUID = 1L;
private String productNo;
private String productName;
private int number;
private int money;
private int id;
public DailySales(String productNo, String productName, int
number, int money)
{
this.productNo = productNo;
this.productName = productName;
this.number = number;
this.money = money;
}
public String getProductNo()
{
return productNo;
}
public void setProductNo(String productNo)
{
this.productNo = productNo;
}
public String getProductName()
{
return productName;
}
public void setProductName(String productName)
{
this.productName = productName;
}
public int getNumber()
{
return number;
}

public void setNumber(int number)
{
this.number = number;
}
public int getMoney()
{
return money;
}
public void setMoney(int money)
{
this.money = money;
}
public int getId()
{
return id;
}
public void setId(int id)
{
this.id = id;
}
}
2.创建 DailySalesDataSource.java,这是报表的数据源。这个类实现了 jasperreports 中提
供的数据源接口 JRDataSource,实现其中的两个方法:next()和 getFieldValue(JRField
$eld)。
package com.bjdv.catv.view;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRField;
public class DailySalesDataSource implements JRDataSource{
/**
*测试数据,实际项目中是动态获取,也不一定是数组,可以是其它的数据类型.
*/
private Object[][] data =
{
{"货号1", "物品1", 1,1000},

{"货号2", "物品2", 2,2000},
{"货号3", "物品3", 3,3000},
{"货号4", "物品4", 4,4000},
{"货号5", "物品5", 5,5000},
{"货号6", "物品6", 6,6000},
{"货号7", "物品7", 7,7000},
{"货号8", "物品8", 8,8000},
{"货号9", "物品9", 9,9000},
{"货号10", "物品10", 10,10000}
};
private int index = -1;
public DailySalesDataSource()
{
}
/**
*实现了JRDataSource中的方法.判断是否还有下一个.
*/
public boolean next() throws JRException
{
index++;
return (index < data.length);
}
/**
*实现了JRDataSource中的方法.
*@paramfield是对应报表中的要填充的字段的名称.
*/
public Object getFieldValue(JRField field) throws JRException
{
Object value = null;
String fieldName = field.getName();
if ("id".equals(fieldName))
{
value = index+1;
}
else if ("productNo".equals(fieldName))
{
value = data[index][0];
}
剩余11页未读,继续阅读

sllizhimei
- 粉丝: 3
- 资源: 4
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


安全验证
文档复制为VIP权益,开通VIP直接复制

- 1
- 2
前往页