Struts2Spring3MyBatis3整合ExtJS完成ColumnTree 二Word文件下载.docx
- 文档编号:20287374
- 上传时间:2023-01-21
- 格式:DOCX
- 页数:19
- 大小:41.28KB
Struts2Spring3MyBatis3整合ExtJS完成ColumnTree 二Word文件下载.docx
《Struts2Spring3MyBatis3整合ExtJS完成ColumnTree 二Word文件下载.docx》由会员分享,可在线阅读,更多相关《Struts2Spring3MyBatis3整合ExtJS完成ColumnTree 二Word文件下载.docx(19页珍藏版)》请在冰豆网上搜索。
/package>
/struts>
启动后,可以看到首页index的页面就基本整合完成。
4、首先看看Action代码,代码如下:
packagecom.hoo.action;
importjava.util.ArrayList;
importjava.util.List;
importjavax.inject.Inject;
importjavax.inject.Named;
importorg.springframework.stereotype.Component;
importcom.hoo.biz.AccountBiz;
importcom.hoo.entity.Account;
importcom.opensymphony.xwork2.ActionSupport;
/**
*<
b>
function:
/b>
AccountAction
*@authorhoojo
*@createDate2011-5-11下午12:
03:
05
*@fileAccountAction.java
*@packagecom.hoo.action
*@projectS2SMyBatis
*@blog
*@emailhoojo_@
*@version1.0
*/
@Component
publicclassAccountActionextendsActionSupport{
*@authorHoojo
privatestaticfinallongserialVersionUID=-973535478139284399L;
@Inject
@Named("
accountBiz"
)
privateAccountBiz<
Account>
biz;
privateAccountacc;
privateList<
results=newArrayList<
();
publicList<
getResults(){
returnresults;
}
publicAccountgetAcc(){
returnacc;
publicvoidsetAcc(Accountacc){
this.acc=acc;
publicStringadd()throwsException{
if(!
biz.addAccount(acc)){
this.addActionMessage("
添加数据失败"
);
returnERROR;
returnSUCCESS;
publicStringshow()throwsException{
results=biz.getList();
return"
show"
;
publicStringremove()throwsException{
publicStringedit()throwsException{
publicStringtreeData()throwsException{
tree"
}
这个Action被注解成Component,那么在spring的applicationContext配置文件中就不需要进行<
bean/>
标签的配置了。
上面注入了AccountDao,完成相关操作。
5、由于Struts2要和Spring进行整合,所以struts的配置会有点不同
actionname="
account"
class="
accountAction"
resulttype="
redirect"
account!
show.action<
/result>
resultname="
/show.jsp<
/action>
上面的class不再是AccountAction的classpath,而是spring容器中配置的bean。
就是通过@Component注解过的AccountAction,被注解注释过后它的id默认是类名称首字母小写。
所以上面的action的配置是accountAction。
6、由于要整合ExtJS,所以这里用到struts2-json-plugin-2.2.3.jar这个插件,将其加入到lib库中,struts.xml更改成:
json-default"
global-results>
error"
/error.jsp<
/global-results>
type="
json"
paramname="
excludeProperties"
acc<
/param>
AccountAction中的treeData方法返回的tree,在account这个action配置中找到tree的result,将result的type配置成json。
表示该result的数据以json的方式展示。
tree这个result还配置了一个param,名称为excludeProperties表示排除的属性。
这个参数将排除当前Action中的acc属性。
也就是说这个属性将不会得到json的转换。
其他属性将会被转换成json。
7、前台页面
index.jsp
body>
ahref="
show.action"
显示所有<
/a>
br>
add.jsp"
添加数据<
br/>
treeData.action"
JSON<
/body>
show.jsp
%@pagelanguage="
java"
import="
java.util.*"
pageEncoding="
%>
%@taglibprefix="
s"
uri="
/struts-tags"
%>
%
Stringpath=request.getContextPath();
StringbasePath=request.getScheme()+"
:
//"
+request.getServerName()+"
+request.getServerPort()+path+"
/"
DOCTYPEHTMLPUBLIC"
-//W3C//DTDHTML4.01Transitional//EN"
html>
head>
basehref="
%=basePath%>
title>
showalldata<
/title>
metahttp-equiv="
pragma"
content="
no-cache"
cache-control"
expires"
0"
/head>
s:
iteratorvalue="
results"
status="
var="
data"
${data}<
===>
propertyvalue="
#data.accountId"
#
#data.username"
#data.password"
#data.createTime"
/>
datename="
format="
yyyy-MM-dd"
ahref="
remove.action"
删除<
|<
edit.action"
修改<
/s:
iterator>
/html>
Struts标签和OGNL表达式显示数据
add.jsp
add<
formaction="
add.action"
method="
post"
textfieldname="
acc.username"
passwordname="
acc.password"
submitvalue="
提交"
submit>
form>
四、整合ExtJS
1、添加ext的库,版本是2.2.2
需要添加column-tree.css
/*
*ExtJSLibrary2.2.1
*Copyright(c)2006-2009,ExtJS,LLC.
*licensing@
*
.x-column-tree.x-tree-node{
zoom:
1;
.x-column-tree.x-tree-node-el{
/*border-bottom:
1pxsolid#eee;
borders?
.x-column-tree.x-tree-selected{
background:
#d9e8fb;
.x-column-tree.x-tree-nodea{
line-height:
18px;
vertical-align:
middle;
.x-column-tree.x-tree-nodeaspan{
.x-column-tree.x-tree-node.x-tree-selectedaspan{
transparent;
color:
#000;
.x-tree-col{
float:
left;
overflow:
hidden;
padding:
01px;
.x-tree-col-text,.x-tree-hd-text{
-o-text-overflow:
ellipsis;
text-overflow:
3px3px3px5px;
white-space:
nowrap;
font:
normal11pxarial,tahoma,helvetica,sans-serif;
.x-tree-headers{
#f9f9f9url(../ext2/resources/images/default/grid/grid3-hrow.gif)repeat-x0bottom;
cursor:
default;
.x-tree-hd{
border-left:
border-right:
1pxsolid#d0d0d0;
.task{
background-image:
url(../shared/icons/fam/cog.png)!
important;
.task-folder{
url(../shared/icons/fam/folder_go.png)!
Ext.tree.ColumnTree.js
Ext.tree.ColumnTree=Ext.extend(Ext.tree.TreePanel,{
lines:
false,
borderWidth:
Ext.isBorderBox?
0:
2,//thecombinedleft/rightborderforeachcell
cls:
'
x-column-tree'
onRender:
function(){
Ext.tree.ColumnTree.superclass.onRender.apply(this,arguments);
this.headers=this.body.createChild(
{cls:
x-tree-headers'
},this.innerCt.dom);
varcols=this.columns,c;
vartotalWidth=0;
for(vari=0,len=cols.length;
i<
len;
i++){
c=cols[i];
totalWidth+=c.width;
this.headers.createChild({
x-tree-hd'
+(c.cls?
c.cls+'
-hd'
),
cn:
{
x-tree-hd-text'
html:
c.header
},
style:
width:
+(c.width-this.borderWidth)+'
px;
});
this.headers.createChild({cls:
x-clear'
});
//preventfloatsfromwrappingwhenclipped
this.headers.setWidth(totalWidth);
this.innerCt.setWidth(totalWidth);
Ext.tree.ColumnNodeUI=Ext.extend(Ext.tree.TreeNodeUI,{
focus:
Ext.emptyFn,//preventoddscrollingbehavior
renderElements:
function(n,a,targetNode,bulkRender){
this.indentMarkup=n.parentNode?
n.parentNode.ui.getChildIndent():
'
vart=n.getOwnerTree();
varcols=t.columns;
varbw=t.borderWidth;
varc=cols[0];
varbuf=[
liclass="
x-tree-node"
divext:
tree-node-id="
n.id,'
class="
x-tree-node-elx-tree-node-leaf'
a.cls,'
divclass="
x-tree-col"
style="
c.width-bw,'
spanclass="
x-tree-node-indent"
this.indentMarkup,"
/span>
imgsrc="
this.emptyIcon,'
x-tree-ec-iconx-tree-elbow"
a.icon||this.emptyIcon,'
x-tree-node-icon'
(a.icon?
"
x-tree-node-inline-icon"
:
),(a.iconCls?
+a.iconCls:
),'
unselectable="
on"
ahidefocus="
x-tree-node-anchor"
href="
a.href?
a.href:
#"
'
tabIndex="
1"
a.hrefTarget?
target="
+a.hrefTarget+'
'
spanunselectable="
n.text||(c.renderer?
c.renderer(a[c.dataIndex],n,a):
a[c.dataIndex]),"
/div>
];
for(vari=1,len=cols.length;
buf.push('
x-tree-col'
(c.cls?
c.cls:
x-tree-col-text"
(c.renderer?
c.renderer(a[c.dataIndex],n,a):
buf.push(
x-clear"
ulclass="
x-tree-node-ct"
display:
none;
/ul>
/li>
if(bulkRender!
==true&
&
n.nextSibling&
n.nextSibling.ui.getEl()){
this.wrap=Ext.DomHelper.insertHtml("
beforeBegin"
n.nextSibling.ui.getEl(),buf.join("
));
}else{
beforeEnd"
targetNode,buf.join("
this.elNode=this.wrap.childNodes[0];
this.ctNode=this.wrap.childNodes[1];
varcs=this.elNode.firstChild.childNodes;
this.indentNode=cs[0];
this.ecNode=cs[1];
this.iconNode=cs[2];
this.anchor=cs[3];
this.textNode=cs[3].firstChild;
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Struts2Spring3MyBatis3整合ExtJS完成ColumnTree Struts2Spring3MyBatis3 整合 ExtJS 完成 ColumnTree
![提示](https://static.bdocx.com/images/bang_tan.gif)
链接地址:https://www.bdocx.com/doc/20287374.html