SSI+Jquery实现增删改查(无刷新).doc_第1页
SSI+Jquery实现增删改查(无刷新).doc_第2页
SSI+Jquery实现增删改查(无刷新).doc_第3页
SSI+Jquery实现增删改查(无刷新).doc_第4页
SSI+Jquery实现增删改查(无刷新).doc_第5页
已阅读5页,还剩19页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

ssi+jquery简单增删改查一、 配置环境加入jar包,我以前写过一个文档,里面已经将jar包写好,请参考:/view/cb62184c852458fb770b56bc.html除了将这些jar包加入后,还得需要几个包,这几个包是jquery所要用到的包commons-beanutils-1.8.3.jar、commons-collections-3.2.1.jar、commons-lang-2.5.jar、commons-logging.jar、dwr4struts2.jar、ezmorph-1.0.6.jar、json-lib-2.2.2-jdk15.jar、jsonplugin-0.31.jar二、 编写后台代码及配置文件1、 写实体beanstudent.javapackage com.vstsoft.model;public class studentprivate int id ;private string username ;private string stuid ;private string email ;private string phone ;private string address ;public int getid() return id;public void setid(int id) this.id = id;public string getusername() return username;public void setusername(string username) this.username = username;public string getstuid() return stuid;public void setstuid(string stuid) this.stuid = stuid;public string getemail() return email;public void setemail(string email) this.email = email;public string getphone() return phone;public void setphone(string phone) this.phone = phone;public string getaddress() return address;public void setaddress(string address) this.address = address;2、 编写dao层及其实现studentdao.javapackage com.vstsoft.dao;import java.util.list;import com.vstsoft.model.student;public interface studentdao public list queryall();/查询全部public boolean save(student student) ;/增加public boolean del(int id) ;/删除public boolean update(student student) ;/更新public student querybyid(int id);/按id查询studentdaoimpl.javapackage com.vstsoft.dao.impl;import java.sql.sqlexception;import java.util.list;import com.ibatis.sqlmap.client.sqlmapclient;import com.vstsoft.dao.studentdao;import com.vstsoft.model.student;public class studentdaoimpl extends student implements studentdao private sqlmapclient sqlmapclient;public void setsqlmapclient(sqlmapclient sqlmapclient) this.sqlmapclient = sqlmapclient;public boolean del(int id) try int b = sqlmapclient.delete(del, id);if(b0)return true;elsereturn false; catch (sqlexception e) e.printstacktrace();return false;public list queryall() list list = null;try list = sqlmapclient.queryforlist(queryall); catch (sqlexception e) e.printstacktrace();return list;public student querybyid(int id) student student = null;try student = (student) sqlmapclient.queryforobject(querybyid, id); catch (sqlexception e) e.printstacktrace();return student;public boolean save(student student) boolean b ;try sqlmapclient.insert(savestu, student);b = true ; catch (sqlexception e) e.printstacktrace();b = false;return b ;public boolean update(student student) boolean b ;try sqlmapclient.update(updatestu, student);b = true; catch (sqlexception e) e.printstacktrace();b = false;return b;3、 编写服务层及其实现studentservice.javapackage com.vstsoft.service;import java.util.list;import com.vstsoft.model.student;public interface studentservice public list queryall();/查询全部public boolean save(student student) ;/增加public boolean del(int id) ;/删除public boolean update(student student) ;/更新public student querybyid(int id);/按id查询studentserviceimpl.javapackage com.vstsoft.service.impl;import java.util.list;import com.vstsoft.dao.studentdao;import com.vstsoft.model.student;import com.vstsoft.service.studentservice;public class studentserviceimpl implements studentservice private studentdao sdao ;public boolean del(int id) boolean b = sdao.del(id);if(b)return true ;elsereturn false;public list queryall() list list = sdao.queryall();return list;public student querybyid(int id) student student = sdao.querybyid(id);return student;public boolean save(student student) boolean b = sdao.save(student);if(b)return true;elsereturn false;public boolean update(student student) boolean b = sdao.update(student);if(b)return true;elsereturn false;public studentdao getsdao() return sdao;public void setsdao(studentdao sdao) this.sdao = sdao;/4、编写控制层actionstudentaction.javapackage com.vstsoft.action;import java.util.list;import javax.servlet.http.httpservletrequest;import javax.servlet.http.httpservletresponse;import net.sf.json.jsonobject;import org.apache.struts2.servletactioncontext;import com.opensymphony.xwork2.actionsupport;import com.vstsoft.model.student;import com.vstsoft.service.studentservice;public class studentaction extends actionsupportprivate studentservice ss ;private list list;private int id ;private string username ;private string stuid;private string phone;private string address;private string email;public string getusername() return username;public void setusername(string username) this.username = username;public int getid() return id;public void setid(int id) this.id = id;public list getlist() return list;public void setlist(list list) this.list = list;public studentservice getss() return ss;public void setss(studentservice ss) this.ss = ss;httpservletrequest request = servletactioncontext.getrequest();public string queryall() throws exception system.out.println(*queryall*);list list = ss.queryall();jsonobject json = new jsonobject();json.accumulate(list, list);system.out.println(json+json);httpservletresponse response = servletactioncontext.getresponse();response.setcontenttype(text/x-json;charset=utf-8);response.setheader(cache-control, no-cache); response.getwriter().print(json.tostring();return null;public string del() throws exception system.out.println(del);system.out.println(id=+this.getid();ss.del(this.getid();return null;public string querybyid() throws exception system.out.println(id=+this.getid();student student = ss.querybyid(this.getid();jsonobject json = new jsonobject();json.accumulate(student, student);system.out.println(json=+json);httpservletresponse response = servletactioncontext.getresponse();response.setcontenttype(text/x-json;charset=utf-8);response.setheader(cache-control, no-cache); response.getwriter().print(json.tostring();return null;public string change() throws exception system.out.println(*change*);student student = new student();student.setusername(this.username);student.setstuid(this.stuid);student.setphone(this.phone);student.setemail(this.email);student.setaddress(this.address);student.setid(this.id);ss.update(student);return null;public string save() throws exception student student = new student();student.setusername(this.username);student.setstuid(this.stuid);student.setphone(this.phone);student.setemail(this.email);student.setaddress(this.address);ss.save(student);return null;public string getstuid() return stuid;public void setstuid(string stuid) this.stuid = stuid;public string getphone() return phone;public void setphone(string phone) this.phone = phone;public string getaddress() return address;public void setaddress(string address) this.address = address;public string getemail() return email;public void setemail(string email) this.email = email;4、 编写配置文件struts.xml !- - applicationcontext.xml classpath:/com/vstsoft/sqlmap/sqlmapconfig.xml lpertieslog4j.appender.stdout=org.apache.log4j.consoleappenderlog4j.appender.stdout.layout=org.apache.log4j.patternlayoutlog4j.appender.stdout.layout.conversionpattern=%d %p %c - %m%.ibatis=mon.jdbc.simpledatasource=mon.jdbc.scriptrunner=.ibatis.sqlmap.engine.impl.sqlmapclientdelegate=debuglog4j.logger.java.sql.connection=debuglog4j.logger.java.sql.statement=debuglog4j.logger.java.sql.preparedstatement=debug,stdoutweb.xmlcontextconfiglocationclasspath*:applicationcontext.xmlstruts2org.apache.struts2.dispatcher.filterdispatcherstruts2/*org.springframework.web.context.contextloaderlistenerindex.jsp configservlet configservlet configservlet /servlet/configservlet sqlmapconfig.xml student.xmlselect * from student order by id ascinsert into student(username,stuid,phone,email,address)values(#username#,#stuid#,#phone#,#email#,#address#)delete from student where id=#id#update student set username=#username#, stuid=#stuid#,phone=#phone# , email=#email#, address=#address# where id = #id#至此,配置工作都已经完成,剩下最重要的一步,那就是编写前台页面了三、 编写前台页面的代码显示学生信息#dialog-overlay width:100%; height:100%; filter:alpha(opacity=50); -moz-opacity:0.5; -khtml-opacity: 0.5; opacity: 0.5; position:absolute; background:#000; top:0; left:0; z-index:3000; display:none; #dialog-box -webkit-box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.5); -moz-box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.5); -moz-border-radius: 5px; -webkit-border-radius: 5px; background:#ffffcc; width:328px; position:absolute; z-index:5000; display:none; #dialog-box .dialog-content text-align:left; padding:10px; margin:13px; color:black; font-family:arial; font-size:11px; a.button margin:10px auto 0 auto; text-align:center; background-color: #e33100; display: block; width:50px; padding: 5px 10px 6px; color: #fff; text-decoration: none; font-weight: bold; line-height: 1; -moz-border-radius: 5px; -webkit-border-radius: 5px; -moz-box-shadow: 0 1px 3px rgba(0,0,0,0.5); -webkit-box-shadow: 0 1px 3px rgba(0,0,0,0.5); text-shadow: 0 -1px 1px rgba(0,0,0,0.25); border-bottom: 1px solid rgba(0,0,0,0.25); position: relative; cursor: pointe

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论