




已阅读5页,还剩57页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
什么是ExtJS?要了解什么是ExtJS,得先了解一下什么是YUI。YUI(Yahoo!UILibrary)是一个开源的JavaScript库,与Ajax、DHTML和DOM等技术一起使用可以用于创建富有交互性的Web应用,它还包含丰富的CSS资源。Ext最初是YUI的一个扩展,然而,它现在也可以扩展自JQuery和Prototype。自1.1版开始,Ext已经可以独立运行,不需要依赖于那些外部库,虽然它仍然是可被集成的一个选项。现在,Ext2.0版可以使用许多不同的基础库,例如YUI、JQuery和Prototype,或者是可以独立的运行。ExtJS是一个非常棒的Ajax框架,可以用来开发富有华丽外观的富客户端应用,能使b/s应用更加具有活力。ExtJS是一个用javascript编写,与后台技术无关的前端ajax框架。因此,可以把ExtJS用在.Net、Java、Php等各种开发语言开发的应用程序中。不多说,先看数据库的设计:droptableifexistsexttree;CREATETABLEexttree(idbigint(11)auto_incrementprimarykey,parentIdbigint(11)NOTNULL,titlevarchar(255)defaultNULL,numberbigint(11)defaultNULL,leafint(4)defaultNULL,urlvarchar(255)defaultNULL);insertintoexttreevalues(null,-1,Root,0,0,null);insertintoexttreevalues(null,1,音乐,0,0,null);insertintoexttreevalues(null,2,轻金属,1,1,null);insertintoexttreevalues(null,2,重金属,2,1,null);insertintoexttreevalues(null,2,R&B,3,1,null);insertintoexttreevalues(null,1,体育,0,0,null);insertintoexttreevalues(null,6,篮球,1,1,null);insertintoexttreevalues(null,6,足球,2,1,null);insertintoexttreevalues(null,6,体操,3,1,null);insertintoexttreevalues(null,1,美食,0,0,null);insertintoexttreevalues(null,10,中国菜,0,0,null);insertintoexttreevalues(null,11,青椒找肉,0,1,null);insertintoexttreevalues(null,10,日本菜,0,0,null);insertintoexttreevalues(null,13,河夫烤鱼,0,1,null);insertintoexttreevalues(null,10,法国菜,0,0,null);insertintoexttreevalues(null,15,爆炒蜗牛,0,1,null);字段number为排列位置1为最上(子节点),leaf表示是子节点或父节点。后台数据处理接口如下:packagecom.exttree.dao;importjava.util.List;importcom.exttree.pojo.Exttree;/*Ext访问数据库接口封装*authorBruceLeey*/publicinterfaceIExtTreeDemo/*根据ID查找对象*paramid*return*throwsException*/publicExttreefindById(Longid)throwsException;/*根据父节点查询所有子节点列表*paramparentId*return*throwsException*/publicListfindChildById(LongparentId)throwsException;/*保存节点*paramnode*throwsException*/publicvoidsave(Exttreenode)throwsException;/*根据ID删除子节点*paramnode*throwsException*/publicvoidremoveChildById(Exttreenode)throwsException;/*修改节点*paramnode*throwsException*/publicvoidmodify(Exttreenode)throwsException;/*执行繁杂的修改语句*paramhql*throwsException*/publicvoidmodifyBySQL(Stringhql)throwsException;/*移除节点*paramid*throwsException*/publicvoidajaxRemoveNode(Longid)throwsException;实现如下:packagecom.exttree.dao;importjava.util.List;importorg.hibernate.Query;importorg.hibernate.Session;importorg.hibernate.Transaction;importorg.springframework.orm.hibernate3.support.HibernateDaoSupport;importcom.exttree.pojo.Exttree;publicclassExtTreeDemoImplextendsHibernateDaoSupportimplementsIExtTreeDemopublicExttreefindById(Longid)throwsExceptionListlist=this.getHibernateTemplate().find(fromExttreeextwhereext.id=?,id);returnlist.size()=1?list.get(0):null;publicListfindChildById(LongparentId)throwsExceptionreturnthis.getHibernateTemplate().find(fromExttreeextwhereext.parentId=?,parentId);publicvoidmodify(Exttreenode)throwsExceptionthis.getHibernateTemplate().merge(node);/相当于SaveOrUpdatepublicvoidremoveChildById(Exttreenode)throwsExceptionStringhql=deletefromExttreetreewheretree.id=+node.getId();Sessionsession=this.getHibernateTemplate().getSessionFactory().openSession();Transactiontm=session.beginTransaction();tm.begin();Queryquery=session.createQuery(hql);query.executeUpdate();mit();publicvoidsave(Exttreenode)throwsExceptionthis.getHibernateTemplate().save(node);publicvoidmodifyBySQL(Stringhql)throwsExceptionSessionsession=this.getHibernateTemplate().getSessionFactory().openSession();Transactiontm=session.beginTransaction();tm.begin();Queryquery=session.createSQLQuery(hql);query.executeUpdate();mit();publicvoidajaxRemoveNode(Longid)throwsExceptionListlist=this.findChildById(id);for(Exttreeobject:list)/移除子节点ajaxRemoveNode(object.getId();Exttreetree=newExttree();/需改进tree.setId(id);this.removeChildById(tree);/父节点始终会移除需要注意的是,如果将removeChildById改成这样:publicvoidremoveChildById(Exttreenode)throwsExceptionthis.getHibernateTemplate().delete(node);将会报此异常:adifferentobjectwiththesameidentifiervaluewasalreadyassociatedwiththesession内存中存在两个实例,但是不是同一个对象,因此Hibernate不知道该删除哪一个,因为在删除之前已构建一个实例,删除时再传递需要删除的对象,因为内存地址不一样,因此报这样的错误,解决办法是重新打开一个Session或者清空当前Session。修改时也是如此,可使用Hibernate的getHibernateTemplate().merge(node);业务层接口如下:packagecom.exttree.service;importjava.util.List;importcom.exttree.pojo.Exttree;/*EXTTree业务逻辑接口封装*authorBruceLeey*/publicinterfaceIExtTreeDemoService/*异步修改标题*paramid*paramtitle*throwsException*/publicvoidajaxModifyTitle(Longid,Stringtitle)throwsException;/*异步移除父节点*paramparentId*throwsException*/publicvoidajaxRemoveParentById(LongparentId)throwsException;/*异步移动节点*paramid*paramoldParentId*paramnewParentId*paramnodeIndex*throwsException*/publicvoidajaxMoveNode(Longid,LongoldParentId,LongnewParentId,LongnodeIndex)throwsException;/*节点向上*paramparentId*paramminIndex*parammaxIndex*throwsException*/publicvoidupNode(intparentId,intminIndex,intmaxIndex)throwsException;/*节点向下*paramparentId*paramminIndex*parammaxIndex*throwsException*/publicvoiddownNode(intparentId,intminIndex,intmaxIndex)throwsException;/*根据ID查找对象*paramid*return*throwsException*/publicExttreefindById(Longid)throwsException;/*根据父节点查询所有子节点列表*paramparentId*return*throwsException*/publicListfindChildById(LongparentId)throwsException;/*修改节点*paramnode*throwsException*/publicvoidmodify(Exttreenode)throwsException;/*保存节点*paramnode*throwsException*/publicvoidsave(Exttreenode)throwsException;实现:packagecom.exttree.service.impl;importjava.util.List;importcom.exttree.dao.IExtTreeDemo;importcom.exttree.pojo.Exttree;importcom.exttree.service.IExtTreeDemoService;publicclassExtTreeDemoServiceImplimplementsIExtTreeDemoServiceprivateIExtTreeDemotreeDAO=null;publicIExtTreeDemogetTreeDAO()returntreeDAO;publicvoidsetTreeDAO(IExtTreeDemotreeDAO)this.treeDAO=treeDAO;publicvoidajaxModifyTitle(Longid,Stringtitle)throwsExceptionExttreenode=treeDAO.findById(id);if(!title.equals(node.getTitle()/当节点标题确认修改了后调用node.setTitle(title);treeDAO.modify(node);publicvoidajaxRemoveParentById(LongparentId)throwsExceptionExttreeobj=treeDAO.findById(parentId);this.downNode(obj.getParentId().intValue(),obj.getNumber().intValue(),-1);treeDAO.ajaxRemoveNode(obj.getId();/移除父节点publicvoidajaxMoveNode(Longid,LongoldParentId,LongnewParentId,LongnodeIndex)throwsExceptionExttreenode=treeDAO.findById(id);intminIndex=node.getNumber().intValue();intmaxIndex=nodeIValue();if(oldParentId=newParentId&minIndex!=maxIndex)if(minIndexmaxIndex)maxIndex=minIndex;minIndex=nodeIValue();this.upNode(oldParentIValue(),minIndex,maxIndex);node.setNumber(nodeIndex);treeDAO.modify(node);if(oldParentId!=newParentId)this.downNode(oldParentIValue(),minIndex,-1);this.upNode(newParentIValue(),maxIndex,-1);node.setNumber(nodeIndex);node.setParentId(newParentId);treeDAO.modify(node);publicvoiddownNode(intparentId,intminIndex,intmaxIndex)throwsExceptionStringBufferhql=newStringBuffer(updateexttreesetnumber=number-1whereparentId=);hql.append(parentId);if(maxIndex!=-1)hql.append(andnumber);hql.append(minIndex);treeDAO.modifyBySQL(hql.toString();publicvoidupNode(intparentId,intminIndex,intmaxIndex)throwsExceptionStringBufferhql=newStringBuffer(updateexttreesetnumber=number+1whereparentId=);hql.append(parentId);if(maxIndex!=-1)hql.append(andnumber=);hql.append(minIndex);treeDAO.modifyBySQL(hql.toString();publicExttreefindById(Longid)throwsExceptionreturntreeDAO.findById(id);publicListfindChildById(LongparentId)throwsExceptionreturntreeDAO.findChildById(parentId);publicvoidmodify(Exttreenode)throwsExceptiontreeDAO.modify(node);publicvoidsave(Exttreenode)throwsExceptiontreeDAO.save(node);主要的数据访问与业务写好之后,接下来将Web的访问控制写好:packagecom.exttree.web;importorg.apache.struts2.ServletActionContext;importcom.exttree.pojo.Exttree;importcom.exttree.service.IExtTreeDemoService;/*Web后端控制器*authorBruceLeey*/publicclassExtTreeActionprivateExttreeextTree=null;privateIExtTreeDemoServiceservice=null;/*添加节点*return*/publicStringsaveNode()throwsExceptionif(!.equals(extTree.getId()&null!=extTree.getId()if(service.findById(extTree.getId()=null)returnERROR;elseservice.modify(extTree);returnSUCCESS;service.save(extTree);returnSUCCESS;/*修改节点*return*/publicStringmodifyNode()throwsExceptionif(null!=extTree.getId()ServletActionContext.getRequest().setAttribute(obj,service.findById(extTree.getId();elseServletActionContext.getRequest().setAttribute(obj,extTree);returnEDIT;/*异步获取数据*return*/publicStringjsonData()throwsExceptionServletActionContext.getRequest().setAttribute(list,service.findChildById(Long.valueOf(ServletActionContext.getRequest().getParameter(id);returnJSON;publicIExtTreeDemoServicegetService()returnservice;publicvoidsetService(IExtTreeDemoServiceservice)this.service=service;publicExttreegetExtTree()returnextTree;publicvoidsetExtTree(ExttreeextTree)this.extTree=extTree;Spring配置如下:classpath:hibernate.cfg.xml本例子中使用了DWR作为异步调用服务器方法,DWR框架配置比较简单,因为例子中的对象由Spring托管,因此需要配置DWR与Spring的交互,首先先看Web.xml中的配置sessionFilterorg.springframework.orm.hibernate3.support.OpenSessionInViewFiltersessionFilter/*struts2.xorg.apache.struts2.dispatcher.FilterDispatcherstruts2.x/*contextConfigLocation/WEB-INF/applicationContext.xmlorg.springframework.web.context.ContextLoaderListenerdwr-invokeruk.ltd.getahead.dwr.DWRS
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年现代物流与供应链优化考试试卷及答案
- 2025年数字媒体艺术专业综合素质考试试题及答案
- 2025年思想政治教育课程考核试题及答案
- 2025年全球健康与公共卫生应急管理课程考试卷及答案
- 2025年环境影响评估师资格考试模拟试卷及答案
- 2025年化学基础知识测试试卷及答案
- 2025年甘肃省陇南市事业单位招聘247人笔试参考题库及答案详解一套
- 2025年中国邮政集团有限公司甘肃省分公司校园招聘笔试模拟试题带答案详解
- 物资计划提报管理制度
- 物资采购会计管理制度
- 2025年心理健康指导师职业资格考试试题及答案
- 石油行业采购物资质量事故案例规律分析课件
- 2025年新高考2卷(新课标Ⅱ卷)英语试卷(含答案解析)
- JG/T 283-2010膨胀玻化微珠轻质砂浆
- 电力法规考试试题及答案
- 2025昆明医科大学海源学院辅导员考试试题及答案
- 2024福建省闽投深海养殖装备租赁有限责任公司招聘7人笔试参考题库附带答案详解
- JGJ406T-2017预应力混凝土管桩技术标准附条文
- 学术英语课程知到章节答案智慧树2023年上海理工大学
- 社会保险业务申报表(申报1表)
- GB/T 18103-2013实木复合地板
评论
0/150
提交评论