Java Classes
Contact.java
package gr.osmosis.report.data;
public class Contact {
String fname;
String lname;
String phone;
public Contact(String fname, String lname, String phone){
this.fname = fname;
this.lname = lname;
this.phone = phone;
}
/**
* @return Returns the fname.
*/
public String getFname() {
return fname;
}
/**
* @param fname The fname to set.
*/
public void setFname(String fname) {
this.fname = fname;
}
/**
* @return Returns the lname.
*/
public String getLname() {
return lname;
}
/**
* @param lname The lname to set.
*/
public void setLname(String lname) {
this.lname = lname;
}
/**
* @return Returns the phone.
*/
public String getPhone() {
return phone;
}
/**
* @param phone The phone to set.
*/
public void setPhone(String phone) {
this.phone = phone;
}
}
ContactListFactory.java
package gr.osmosis.report.data;
public class ContactListFactory {
public Contact[] createContactList(){
Contact[] c = new Contact[4];
c[0] = new Contact("stavros", "kounis", "2310886269");
c[1] = new Contact("dimitris", "kounis", "2310888270");
c[2] = new Contact("dimitris", "adamos", "2310998417");
c[3] = new Contact("nikos", "koufotolis", "2321013770");
return c;
}
}
Report
Create a new BIRT report file (.rptdesign) and name it (for example) contactscript.rptdesign.
Datasources
Change to "Report Design" perspective. Find the "DataExplorer" View and create a new "Data Source -> Script Data Source" (named srcScript).
Now right click on "Data Sets" node and create a new dataset:
Data Set Name: setScript
DataSource: srcScript (we have allready create it above)
Set up columns
Right click in your just created data set (setScript) and select "edit"
In the "Edit Data Set" Window select the node "Output Columns".
Add here 3 entries:
Name / Type
--------------
columnFirstName / Any
columnLastName / Any
columnPhoneNumber / Any
Script code
Select now your Data Set (setScript) and set your report editor to have "Code" tab selected
1. put the below code in open method of your DataSet
count = 0;
cf = new Packages.gr.osmosis.report.data.ContactListFactory();
c = cf.createContactList();
now we have an array of Contacts stored in "c" variable.
2. put the below code in fetch method of your DataSet
if (count < c.length-1){
count ++;
row["columnFirstName"] = c[count].getFname();
row["columnLastName"] = c[count].getLname();
row["columnPhoneNumber"] = c[count].getPhone();
return true;
}
return false;
Report Design
In your report editor change to "Layout" Tab
In Data Explorer View your data set must have 3 children nodes (one for each column you have created). Drag 'n drop each one from Data Explorer View to report's layout view.
Preview
Here is a litle problem when we are working in design mode. Report's script must be able to find our java classes (Contact.java, ContactListFactory.java). Report designer use BIRT's web-app viewer to render (preview) the report. But this WEB-APP does not know where to look for our java classes. This web-app exist as an eclipse plug-in.
for example:
C:\JProgramFiles\eclipse-SDK-3.0.2-win32\eclipse\plugins\org.eclipse.birt.report.viewer_1.0.0
We have to put our classes in a "classes" folder in this web-app. To do this create a "classes" folder at birt\web-inf.
Build Contact.java and ContactListFactory.java and put the produced .class files in this "classes" folder.
Dont forget to create inside "classes" folder the directory structure that match the package name.
for example:
if you just copy paste the code from this post then you must have a path like:
C:\JProgramFiles\eclipse-SDK-3.0.2-win32\eclipse\plugins\org.eclipse.birt.report.viewer_1.0.0\birt\WEB-INF\classes\gr\osmosis\report\data
Now you can preview your report selecting "Preview" tab.
相关推荐
**POJOs(Plain Old Java Objects)** 是Java编程中的一个基本概念,它是指那些没有特殊框架或库依赖,纯粹的、普通的Java对象。在Java世界里,POJOs是面向对象设计的基础,它们通常用来封装数据和业务逻辑。本教程...
《Pojos in Action》是一本专注于Java编程领域中Plain Old Java Objects(POJOs)技术的专业书籍。这本书由Manning出版社出版,旨在深入探讨如何在实际开发中有效地使用POJOs,以及它们在现代Java应用程序设计中的...
IDEA通过Generate.POJOs.groovy映射数据库自动生成对应的Java实体类, 具体逻辑不详细展示,可参考:https://blog.csdn.net/weixin_40375601/article/details/106807644
打开里面的内容,替换idea项目中的Generate POJOs.groovy文件(文件路径:SCratches and Consoles -> extensions -> Database Tools and SQL -> schema - > Generate POJOs.groovy)
《POJOS in Action》是一本专注于简单Java对象(Plain Old Java Objects,简称POJOs)的实战指南,由Manning出版社在2005年出版。POJOs是Java编程中的一个基本概念,它代表那些没有特殊框架依赖、遵循传统Java类结构...
在给定的压缩包文件"MyVo Generate POJOs.groovy.zip"中,包含了一系列以"Generate POJOs.groovy"命名的脚本,如"My Generate POJOs.groovy"、"MyDto Generate POJOs.groovy"、"MyInsertDto Generate POJOs.groovy...
《Pojos In Action》这本书由Chris Richardson撰写,聚焦于使用POJOs(Plain Old Java Objects)设计轻量级Java企业应用的关键问题,通过深入的实例解析,为读者提供了实践指导。该书不仅扩展了Martin Fowler的...
IDEA自带的插件Generate POJOs.groovy 比较简陋,不能生成完整的dao/mapper,切生成的POJO没有注解。没有统一格式化,所以在此基础上进行了扩展能够简单的生成pojo/dao/mapper. 使用时选择目录后会在改目录下生成...
《Pojos in Action》是一本深入探讨Java轻量级解决方案的经典教程,它主要针对企业级应用开发领域,尤其关注EJB(Enterprise JavaBeans)编程模型的局限性以及为何转向POJOs(Plain Old Java Objects)和轻量级框架...
《Pojos in Action - 源码探索与工具运用》 "pojos_in_action_-_src.zip" 这个压缩包文件,暗示我们它包含了与《Pojos in Action》一书相关的源代码。这本书主要讲解了Plain Old Java Objects(POJOs)的使用和实践...
POJOS IN ACTION开发轻量级企业应用程序
springboot jpa 自动生成实体类的 文件 可以拿走直接用 Generate POJOs.groovy
在idea中逆向生成实体
### POJOs in Action:利用轻量级框架开发企业应用 #### 一、概述与背景 《POJOs in Action》是一本针对轻量级Java企业应用开发的实践指南。该书通过构建一个完整的应用程序来深入探讨POJO(Plain Old Java Object...
idea利用自带插件Generate POJOs.groovy生成pojo类。idea可以连接数据库,datagrip集成在里面了。