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入门到精通 英文
IDEA通过Generate.POJOs.groovy映射数据库自动生成对应的Java实体类, 具体逻辑不详细展示,可参考:https://blog.csdn.net/weixin_40375601/article/details/106807644
Manning - Pojos In Action
Manning - Pojos In Action.pdf
IDEA自带的插件Generate POJOs.groovy 比较简陋,不能生成完整的dao/mapper,切生成的POJO没有注解。没有统一格式化,所以在此基础上进行了扩展能够简单的生成pojo/dao/mapper. 使用时选择目录后会在改目录下生成...
MyVo Generate POJOs.groovy生成实体类文件
打开里面的内容,替换idea项目中的Generate POJOs.groovy文件(文件路径:SCratches and Consoles -> extensions -> Database Tools and SQL -> schema - > Generate POJOs.groovy)
POJOS IN ACTION开发轻量级企业应用程序
Pojos In Action Pojos In Action Pojos In Action
《POJOS IN ACTION中文版:用轻量级框架开发企业应用》是一本实践指南,它围绕POJO(普通Java对象)构造了一个完整的应用程序,对框架之间的各种组合进行了详细的举例说明;描述了在采用POJO和轻量级框架如Hibernate...
java轻量级解决方案的经典教程,探讨了ejb编程模型的各种缺陷及为什么使用pojos轻量级框架进行企业级开发
在idea中逆向生成实体
找这本书的话 肯定知道这本书的价值我就不都说的了
springboot jpa 自动生成实体类的 文件 可以拿走直接用 Generate POJOs.groovy
NULL 博文链接:https://sbiigu.iteye.com/blog/255751
POJOs in Action
idea利用自带插件Generate POJOs.groovy生成pojo类。idea可以连接数据库,datagrip集成在里面了。