第二十三章使用jquery的easyUI框架提升用户体验理论部分
本章目标ssh+jquery的easyUI框架实现ajax分页显示及CRUD
数据库和表准备数据库和表准备如下:createdatabaseempdbgouseempdbgoCREATETABLE`dep`(`depid`int(11)NOTNULLAUTO_INCREMENT,`depname`varchar(50)NOTNULL,`depdescript`text,PRIMARYKEY(`depid`),UNIQUEKEY`depname`(`depname`));
数据库和表准备CREATETABLE`emp`(`eid`int(11)NOTNULLAUTO_INCREMENT,`ename`varchar(50)NOTNULL,`sex`varchar(4)DEFAULT男,`address`varchar(200)DEFAULTNULL,`birthday`dateDEFAULTNULL,`depid`int(11)NOTNULL,`photo`varchar(50)DEFAULTNULL,PRIMARYKEY(`eid`),KEY`fk_depid`(`depid`),CONSTRAINT`fk_depid`FOREIGNKEY(`depid`)REFERENCES`dep`(`depid`))
环境准备建立web工程引入struts.2+spring2.5+hibernate3.3的组件包(步骤参考前面课程的讲解)引入fastjson组件包到当前工程(拷贝到WEB-INF/lib目录中),组件包名称如下fastjson-1.1.33.jar编写业务接口和业务实现类。使用注解注入dao,业务和action类
在action中编写相关的方法,关键代码如下
@Controller@Namespace(/)publicclassEmpActionimplementsIEmpAction{privateEmpemp;privateintpage;//easyUI传递的当前页数privateintrows;//easyUI传递的每页记录数privateinteid;@Resource(name=DepBiz)privateIDepBizdepbiz;@Resource(name=EmpBiz)privateIEmpBizebiz;…..get/set方法省略
Save方法代码@Action(value=save_Emp)publicStringsave(){HttpServletResponserep=ServletActionContext.getResponse();rep.setCharacterEncoding(gb2312);try{PrintWriterout=rep.getWriter();Stringmsg=;Stringrpath=ServletActionContext.getRequest().getRealPath(/);//上传文件处理if(emp.getPic()!=null){Stringfname=emp.getPicFileName();Stringext=fname.substring(fname.lastIndexOf(.));Stringnfname=newDate().getTime()+ext;FiledestFile=newFile(rpath+/uppic/+nfname);try{FileUtils.copyFile(emp.getPic(),destFile);emp.setPhoto(nfname);}catch(IOExceptione){e.printStackTrace();}}else{emp.setPhoto(Friend.jpg);}booleanbl=ebiz.save(emp);if(bl){msg=保存成功!;}else{msg=保存失败!;}out.print(msg);out.flush();out.close();}catch(IOExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}returnnull;}
Update方法代码@Action(value=update_Emp)publicStringupdate(){System.out.p
原创力文档

文档评论(0)