Struts+spring+hibernate+birt整合实例(ZJP)

<style><!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1;} @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4;} @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4;} @font-face {font-family:"Lucida Console"; panose-1:2 11 6 9 4 5 4 2 2 4;} @font-face {font-family:"\@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; font-size:10.5pt; font-family:"Calibri","sans-serif";} p.MsoHeader, li.MsoHeader, div.MsoHeader {mso-style-link:"ヘッダー \(文字\)"; margin:0cm; margin-bottom:.0001pt; text-align:center; layout-grid-mode:char; border:none; padding:0cm; font-size:9.0pt; font-family:"Calibri","sans-serif";} p.MsoFooter, li.MsoFooter, div.MsoFooter {mso-style-link:"フッター \(文字\)"; margin:0cm; margin-bottom:.0001pt; layout-grid-mode:char; font-size:9.0pt; font-family:"Calibri","sans-serif";} p.MsoAcetate, li.MsoAcetate, div.MsoAcetate {mso-style-link:"吹き出し \(文字\)"; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; font-size:9.0pt; font-family:"Calibri","sans-serif";} p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph {margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; text-indent:21.0pt; font-size:10.5pt; font-family:"Calibri","sans-serif";} span.a {mso-style-name:"ヘッダー \(文字\)"; mso-style-link:ヘッダー;} span.a0 {mso-style-name:"フッター \(文字\)"; mso-style-link:フッター;} span.a1 {mso-style-name:"吹き出し \(文字\)"; mso-style-link:吹き出し; font-family:"Calibri","sans-serif";} /* Page Definitions */ @page Section1 {size:595.3pt 841.9pt; margin:35.45pt 56.65pt 42.55pt 35.45pt; layout-grid:15.6pt;} div.Section1 {page:Section1;} /* List Definitions */ ol {margin-bottom:0cm;} ul {margin-bottom:0cm;} --></style><style mce_bogus="1"> /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1;} @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4;} @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4;} @font-face {font-family:"Lucida Console"; panose-1:2 11 6 9 4 5 4 2 2 4;} @font-face {font-family:"\@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; font-size:10.5pt; font-family:"Calibri","sans-serif";} p.MsoHeader, li.MsoHeader, div.MsoHeader {mso-style-link:"ヘッダー \(文字\)"; margin:0cm; margin-bottom:.0001pt; text-align:center; layout-grid-mode:char; border:none; padding:0cm; font-size:9.0pt; font-family:"Calibri","sans-serif";} p.MsoFooter, li.MsoFooter, div.MsoFooter {mso-style-link:"フッター \(文字\)"; margin:0cm; margin-bottom:.0001pt; layout-grid-mode:char; font-size:9.0pt; font-family:"Calibri","sans-serif";} p.MsoAcetate, li.MsoAcetate, div.MsoAcetate {mso-style-link:"吹き出し \(文字\)"; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; font-size:9.0pt; font-family:"Calibri","sans-serif";} p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph {margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; text-indent:21.0pt; font-size:10.5pt; font-family:"Calibri","sans-serif";} span.a {mso-style-name:"ヘッダー \(文字\)"; mso-style-link:ヘッダー;} span.a0 {mso-style-name:"フッター \(文字\)"; mso-style-link:フッター;} span.a1 {mso-style-name:"吹き出し \(文字\)"; mso-style-link:吹き出し; font-family:"Calibri","sans-serif";} /* Page Definitions */ @page Section1 {size:595.3pt 841.9pt; margin:35.45pt 56.65pt 42.55pt 35.45pt; layout-grid:15.6pt;} div.Section1 {page:Section1;} /* List Definitions */ ol {margin-bottom:0cm;} ul {margin-bottom:0cm;}</style>

Step1:

新建web项目并添加strutsspringhibernate支持,再此不再多加描述。

Step2

添加birtReport支持,当添加成功后,你后发现项目中会多出几个文件夹,同时web.xml文件中也会多出很多配置,当然这个不比你操心,eclipse已经为你配置ok了。下一步就是开始了!目录结构如下:

Struts+spring+hibernate+birt整合实例(ZJP)Struts+spring+hibernate+birt整合实例(ZJP)

下一步,新建report文件Struts+spring+hibernate+birt整合实例(ZJP)

Struts+spring+hibernate+birt整合实例(ZJP)

点击yes进入报表设计视图

Struts+spring+hibernate+birt整合实例(ZJP)

在此处新建数据源(注意选择scriptDataSource)点击finish

Struts+spring+hibernate+birt整合实例(ZJP)

下一步,新建数据集。具体怎样建,相信你肯定会的。再此不做描述!

Struts+spring+hibernate+birt整合实例(ZJP)

OK,到此,birt基本上已经完成。下一步到action内设置数据集List,或其他集合类。

在此我采用的是session方法,把结果集放入session范围内,然后转到带有report标签的jsp页面,然后在报表文件的脚本编辑器内编写脚本,主要用到,数据集的openfentchclose三个方法。

具体写法:

session范围内有一个listlist内为pojo

则在open内写入:(open负责初始化数据)

importPackage(Packages.javax.servlet.http);

req=reportContext.getHttpServletRequest();

session=req.getSession();

params=new Packages.com.yourPOJOPackage.Class();(此处为list内的对象所在的包的完整路径)

list=session.getAttribute("list");

iteratorparams=list.iterator();

Struts+spring+hibernate+birt整合实例(ZJP)

Struts+spring+hibernate+birt整合实例(ZJP)

Fetch内开始遍历(此写法只是模拟,根据实际项目变动)

if(iteratorparams.hasNext()==false){

return false;

}

params=iteratorparams.next();

row[1]=params.getBillnumber();

row[2]=params.getCustomerByCustomid1().getClabel();

row[3]=params.getProduct().getPlabel();

return true;

COLSE内清空open内创建的对象

Ok,运行项目,之后,你就会看到,你的报表结果了!

注意:

1、 MyEclipse自动加载report后,有时会报监听错误,那是因为缺少包所知,解决方法,就是把birt runningtime内的例子所用的jar包拷到你的lib内部一般可以解决!

2、 如果报告hibernate lazy错误的话,那就把hibernate pojo映射文件里面的class节点内加入lazy=false”就ok

3、 还有就是,在遍历(fetch)是,不要写错取值方法,要不然回报找不到getXX方法,的错误

你可能感兴趣的:(eclipse,spring,Hibernate,struts,MyEclipse)