




已阅读5页,还剩24页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
SSH实现的增删改查实例 分类: ssh 2010-10-01 17:12 4591人阅读 评论(7) 收藏 举报 一.整合步骤1.通过MyEclipse向导,添加struts功能2.通过MyEclipse向导,添加Hibernate3功能:生成会话工厂的那个步骤中一定要将那个对号要去掉,不能由hibernate来生成,而是交给Spring来生成;还有就是导入jar包的时候选择复制到lib目录下这一项。3.通过MyEclipse向导,导入实现Spring功能,注意导入jar包的时候选择复制到lib目录下这一项。3.利用MyEclipse反向工程的方法,以Spring生成dao对象的方式创建Hibernate DAO,相关POJO及其xxx.hbm.xml。4. DAO实现类加入Transactional标记。5. 修改applicationContext.xml文件,增加Spring事务管理、DAO等bean的配置。6. 编写action类。7. 在applicationContext.xml文件中添加Action的代理bean。8. 在struts的配置文件中,添加相应的Action,类名指向Spring中的代理bean,并加入和。9. 编写Jsp文件。10. 发布web项目。11. 启动web服务器,运行项目二.SSH实现关于书籍增删改查实例1.创建mysql数据库及其表create database book;create table book(id int not null primary key auto_increment,bookname varchar(30),bookauthor varchar(30);2.表现层(1)index.jsp(首页)java view plaincopyprint?1. 2. 3. 4. 5. 6. 欢迎7. 8. 9. 查看书籍列表10. 11. (2)list.jsp(书籍列表页面)c-sharp view plaincopyprint?1. 2. 3. 4. 9. 10. 11. 12. basehref=13. 书籍列表页面14. 15. 16. 17. /*给链接加入鼠标移过变色和去除下划线功能*/24. a:hover25. color:red;26. text-decoration:none27. 28. 29. 30. 书籍列表页面31. 32. 33. 34. 35. 36. 38. 39. 40. 书籍ID41. 42. 43. 书籍名称44. 45. 46. 作者47. 48. 49. 价格50. 51. 52. 操作53. 54. 55. 56. 57. 58. 59. $book.id60. 61. 62. $book.bookname63. 64. 65. $book.bookauthor66. 67. 68. $book.bookprice69. 70. 71. ahref=/book.do?method=modifybook&id=$book.id修改72. ahref=/book.do?method=deletebook&id=$book.id删除73. 74. 75. 76. 77. 78. 79. 抱歉,没有找到相关的记录!80. 81. ahref=/new.jsp添加书籍82. formaction=/book.do?method=searchbookmethod=postonsubmit=returncheckSearchForm(this);83. 84. 85. 查找书籍86. 87. 书籍名:88. 89. 90. 91. 92. 93. (3)new.jsp(新增书籍页面)c-sharp view plaincopyprint?1. 2. 3. 4. 5. 6. 7. 添加书籍8. 9. 10. 11. 12. 13. 14. 15. 添加书籍16. 17. formaction=/book.do?method=addbookonsubmit=returncheckForm(this);method=post18. 19. 20. 21. 22. 书籍名:23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 作者:33. 34. 35. 36. 37. 38. 39. 40. 41. 价格:42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. inputtype=buttononclick=document.location=/book.do?method=listbook;62. value=63. 返回列表64. 65. (4)edit.jsp(书籍修改页面)c-sharp view plaincopyprint?1. 2. 3. 4. 5. 修改书籍6. 7. 8. 9. 10. 11. 12. 13. 修改书籍14. 15. formaction=/book.do?method=updatebookonsubmit=returncheckForm(this);method=post16. 17. 18. 19. 20. 21. 书籍名:22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 作者:32. 33. 34. 35. 36. 37. 38. 39. 40. 价格:41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. (5)error.jsp(错误公用页面)c-sharp view plaincopyprint?1. 2. 7. 8. 9. 10. basehref=11. 出错了!12. 13. 14. 出错了!15. 详细信息是:16. $message17. 返回18. 19. (6)form.jsc-sharp view plaincopyprint?1. /验证表单输入不为空的脚本代码 2. functioncheckForm(form)3. if(form.bookname.value=)4. alert(书名不能为空!);5. form.bookname.focus();6. returnfalse;7. 8. if(form.bookauthor.value=)9. alert(作者不能为空!);10. form.bookauthor.focus();11. returnfalse;12. 13. if(form.bookprice.value=)14. alert(价格不能为空!);15. form.bookprice.focus();16. returnfalse;17. 18. returntrue;19. 20. functioncheckSearchForm(form)21. if(form.bookname.value.match(/s*$/)22. alert(查询条件不能为空!);23. form.bookname.focus();24. returnfalse;25. 26. returntrue;27. 3.公用类及其javabean(1)EncodingFilter.java(过滤器)c-sharp view plaincopyprint?1. packagefilter;2. importjava.io.IOException;3. importjavax.servlet.Filter;4. importjavax.servlet.FilterChain;5. importjavax.servlet.FilterConfig;6. importjavax.servlet.ServletException;7. importjavax.servlet.ServletRequest;8. importjavax.servlet.ServletResponse;9. publicclassEncodingFilterimplementsFilter10. protectedFilterConfigconfig;11. protectedStringEncoding=null;12. publicvoidinit(FilterConfigconfig)throwsServletException13. this.config=config;14. this.Encoding=config.getInitParameter(Encoding);15. 16. publicvoiddoFilter(ServletRequestrequest,ServletResponseresponse,17. FilterChainchain)throwsIOException,ServletException18. if(request.getCharacterEncoding()=null)19. if(Encoding!=null)20. request.setCharacterEncoding(Encoding);21. response.setCharacterEncoding(Encoding);22. 23. 24. chain.doFilter(request,response);25. 26. publicvoiddestroy()27. 28. (2)book.javac-sharp view plaincopyprint?1. packagedao;2. /*3. *Bookentity.authorMyEclipsePersistenceTools4. */5. publicclassBookimplementsjava.io.Serializable6. /Fields 7. privateIntegerid;8. privateStringbookname;9. privateStringbookauthor;10. privateFloatbookprice;11. /Constructors 12. /*defaultconstructor*/13. publicBook()14. 15. /*fullconstructor*/16. publicBook(Stringbookname,Stringbookauthor,Floatbookprice)17. this.bookname=bookname;18. this.bookauthor=bookauthor;19. this.bookprice=bookprice;20. 21. /Propertyaccessors 22. publicIntegergetId()23. returnthis.id;24. 25. publicvoidsetId(Integerid)26. this.id=id;27. 28. publicStringgetBookname()29. returnthis.bookname;30. 31. publicvoidsetBookname(Stringbookname)32. this.bookname=bookname;33. 34. publicStringgetBookauthor()35. returnthis.bookauthor;36. 37. publicvoidsetBookauthor(Stringbookauthor)38. this.bookauthor=bookauthor;39. 40. publicFloatgetBookprice()41. returnthis.bookprice;42. 43. publicvoidsetBookprice(Floatbookprice)44. this.bookprice=bookprice;45. 46. 4.DAO层BookDAO.javac-sharp view plaincopyprint?1. packagedao;2. importjava.util.List;3. importorg.hibernate.LockMode;4. importorg.hibernate.Query;5. importorg.slf4j.Logger;6. importorg.slf4j.LoggerFactory;7. importorg.springframework.context.ApplicationContext;8. importorg.springframework.context.support.ClassPathXmlApplicationContext;9. importorg.springframework.orm.hibernate3.support.HibernateDaoSupport;10. importorg.springframework.transaction.annotation.Transactional;11. /*12. *Adataaccessobject(DAO)providingpersistenceandsearchsupportforBook13. *entities.Transactioncontrolofthesave(),update()anddelete()operations14. *candirectlysupportSpringcontainer-managedtransactionsortheycanbe15. *augmentedtohandleuser-managedSpringtransactions.Eachofthesemethods16. *providesadditionalinformationforhowtoconfigureitforthedesiredtype17. *oftransactioncontrol.18. *19. *seedao.Book20. *authorMyEclipsePersistenceTools21. */22. Transactional23. publicclassBookDAOextendsHibernateDaoSupport24. privatestaticfinalLoggerlog=LoggerFactory.getLogger(BookDAO.class);25. /propertyconstants 26. publicstaticfinalStringBOOKNAME=bookname;27. publicstaticfinalStringBOOKAUTHOR=bookauthor;28. publicstaticfinalStringBOOKPRICE=bookprice;29. protectedvoidinitDao()30. /donothing 31. 32. publicvoidsave(BooktransientInstance)33. log.debug(savingBookinstance);34. try35. getHibernateTemplate().save(transientInstance);36. log.debug(savesuccessful);37. catch(RuntimeExceptionre)38. log.error(savefailed,re);39. throwre;40. 41. 42. publicvoidupdate(BooktransientInstance)43. log.debug(savingBookinstance);44. try45. getHibernateTemplate().update(transientInstance);46. log.debug(savesuccessful);47. catch(RuntimeExceptionre)48. log.error(savefailed,re);49. throwre;50. 51. 52. publicvoiddelete(BookpersistentInstance)53. log.debug(deletingBookinstance);54. try55. getHibernateTemplate().delete(persistentInstance);56. log.debug(deletesuccessful);57. catch(RuntimeExceptionre)58. log.error(deletefailed,re);59. throwre;60. 61. 62. publicBookfindById(java.lang.Integerid)63. log.debug(gettingBookinstancewithid:+id);64. try65. Bookinstance=(Book)getHibernateTemplate().get(dao.Book,id);66. returninstance;67. catch(RuntimeExceptionre)68. log.error(getfailed,re);69. throwre;70. 71. 72. publicListfindByExample(Bookinstance)73. log.debug(findingBookinstancebyexample);74. try75. Listresults=getHibernateTemplate().findByExample(instance);76. log.debug(findbyexamplesuccessful,resultsize:77. +results.size();78. returnresults;79. catch(RuntimeExceptionre)80. log.error(findbyexamplefailed,re);81. throwre;82. 83. 84. publicListfindByProperty(
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 辅警礼仪的意义
- 农业银行2025常州市小语种岗笔试题及答案
- 邮储银行2025辽源市笔试行测高频题及答案
- 工商银行2025无锡市秋招笔试创新题型专练及答案
- 建设银行2025镇江市结构化面试15问及话术
- 2025年3D打印的医疗器械开发
- 2025年3D打印的3D打印材料技术
- 辅导员任职知识培训课件
- 中国银行2025秋招笔试专业知识题专练及答案辽宁地区
- 邮储银行2025平顶山市数据分析师笔试题及答案
- 做最勇敢的自己
- 《诚信是金》班会课件
- 药房用药小知识培训课件
- 乳腺癌图文课件版
- 《支气管动脉栓塞术》课件
- 子宫肌瘤-妇产科课件
- 2024-2025年江苏专转本英语历年真题(含答案)
- GB/T 44808.1-2024人类工效学无障碍设计第1部分:消费品中的语音提示
- 《机器人驱动与运动控制》全套教学课件
- 包装箱制作合作协议书范文模板
- 电商平台知识产权保护与维权服务合同
评论
0/150
提交评论