1、创建一个javabean对象
import java.io.Serializable; public class GoodPrint implements Serializable{ /** * */ private static final long serialVersionUID = 1L; private String goodName; private String goodNo; private String barcode; private java.math.BigDecimal quantity; private String quantityUnit; public GoodPrint(){ } public GoodPrint(String goodName,String goodNo,String barcode,java.math.BigDecimal quantity,String quantityUnit){ this.goodName=goodName; this.goodNo=goodNo; this.barcode=barcode; this.quantity=quantity; this.quantityUnit=quantityUnit; } public String getGoodName() { return goodName; } public void setGoodName(String goodName) { this.goodName = goodName; } public String getGoodNo() { return goodNo; } public void setGoodNo(String goodNo) { this.goodNo = goodNo; } public String getBarcode() { return barcode; } public void setBarcode(String barcode) { this.barcode = barcode; } public java.math.BigDecimal getQuantity() { return quantity; } public void setQuantity(java.math.BigDecimal quantity) { this.quantity = quantity; } public String getQuantityUnit() { return quantityUnit; } public void setQuantityUnit(String quantityUnit) { this.quantityUnit = quantityUnit; } }
2、工具--》选项--》classpath,导入\WebContent\WEB-INF\classes ,并打钩该选项。
3、创建域字段,如下:
一、用ireport创建数据源,如下:
创建一个工厂类,如下:
public class GoodsFactory { private static GoodPrint[] data={new GoodPrint("GOO1","A","GOO1A",new BigDecimal(10),"M"), new GoodPrint("GOO2","B","GOO2B",new BigDecimal(20),"PCS")}; public static Object[] getBeanArray() { return data; } public static Collection<?> getBeanCollection() { return Arrays.asList(data); } }
导入工厂类
创建Text报表,如下:
二、后台创建数据源如下,如下:
String root_path=request.getRootPath(); String reportFilePath = root_path + "report/Test.jasper"; List goodList=new ArrayList<Goods>(); goodList.add(new GoodPrint("GOO1","A","GOO1A",new BigDecimal(10),"M")); goodList.add(new GoodPrint("GOO2","B","GOO2B",new BigDecimal(20),"PCS")); // JRDataSource dataSource = this.createDataSource(); JRDataSource dataSource = new JRBeanCollectionDataSource(goodList);; // Map<String, Object> parameters = new HashMap<String, Object>(); // List dataList =new ArrayList(); // parameters.put("dataList", dataList); JasperReport report = (JasperReport)JRLoader.loadObject(reportFilePath); JasperPrint jasperPrint = JasperFillManager.fillReport(report, null, dataSource); String repTpl="123"; JasperExportManager.exportReportToPdfFile(jasperPrint,root_path+"report/123.pdf"); // JasperRunManager.runReportToHtmlFile(root_path+"report/123.pdf",null,null); //如果创建报表成功,则转向该报表,其实可以把报表套在框架内,这样实现比较有意义的报表格式。 response.sendRedirect("report2.html"); // JasperFillManager.fillReport(report, parameters, dataSource); // OutputStream ouputStream = response.getOutputStream(); // response.setContentType("application/pdf"); // response.setCharacterEncoding("UTF-8"); // String repName=URLEncoder.encode("物料报表", "UTF-8"); // response.setHeader("Content-Disposition", "attachment; filename=\""+repName+"\".pdf"); // // // 使用JRPdfExproter导出器导出pdf // JRPdfExporter exporter = new JRPdfExporter(); // exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); // exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream); // exporter.exportReport(); // ouputStream.close();
预览结果,如下:
相关推荐
iReport使用JavaBean做数据源
ireport利用javabean做数据源.docx
IREPORT使用JAVABEAN作为报表数据源IREPORT使用JAVABEAN作为报表数据源IREPORT使用JAVABEAN作为报表数据源
iReport使用JavaBean作为数据源——最简单的示例。 包含: 1、Java源文件(JavaBean)。 2、iReport的报表源文件(jrxml)。 3、详细的说明。
下载包含程序源码,lib包,ireport创建模板操作文档,说明。程序可以在java myeclipse环境下直接运行。jasperreport版本6.3.1,ireport为5.6.0
简单明了利用javabean做数据源,实现ireport报表功能
图示ireport中使用javabean作数据源开发基于jasperreports报表过程
一看就会的实例。能够很快上手ireport
ireport中使用javabean作数据源开发jasperreports报表的详细过程 附有图片
在网上找了很多ireport基于...对于bean中的子报表集合数据源怎么获取,始终不成功。现经过尝试终于弄明白是怎么回事了,上传以供分享。因从事IT工作,经常下载无积分,所有收一点点积分。祝大家研究顺利,共同进步!
本文档包含报表模板以及往模板嵌入一个子报表的全部过程,并包含完整导出PDF的SourceCode
利用javabean数据源,ireport入门级普通报表和子报表
這是兩個用java作數據源的例子: 其中 javaBean 為用javaBean作數據源的例子 test 為用自定義數據源的例子 兩個例子都通過測試 想要的朋友可以下載看看! 祝大家玩得開心!
NULL 博文链接:https://shouzhang1-2.iteye.com/blog/1973767
ireport使用javabean做数据源