当前位置:   article > 正文

基于SSH框架的增删改查实例附带源码_ssh增删查改源码

ssh增删查改源码

一步一教你搭建SSH框架,实现简单的增删改查功能

一、首先创建一个Java web项目,并按下图建好项目目录


二、在网上搜索ssh所需jar包,并将其放到WEB_INF下的lib里面(这里截图了部分)


三、如下图配置web.xml(添加spring监听器以及struts过滤器等)

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  3. <display-name>ssh</display-name>
  4. <welcome-file-list>
  5. <welcome-file>index.jsp</welcome-file>
  6. </welcome-file-list>
  7. <!-- ########## 过滤器 ########## -->
  8. <!-- OpenSessionInView -->
  9. <filter>
  10. <filter-name>OpenSessionInView</filter-name>
  11. <filter-class>
  12. org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
  13. </filter-class>
  14. <init-param>
  15. <param-name>singleSession</param-name>
  16. <param-value>true</param-value>
  17. </init-param>
  18. </filter>
  19. <filter-mapping>
  20. <filter-name>OpenSessionInView</filter-name>
  21. <url-pattern>/*</url-pattern>
  22. </filter-mapping>
  23. <!-- 配置字符过滤 -->
  24. <filter>
  25. <filter-name>setCharactor</filter-name>
  26. <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  27. <init-param>
  28. <param-name>encoding</param-name>
  29. <param-value>UTF-8</param-value>
  30. </init-param>
  31. </filter>
  32. <filter-mapping>
  33. <filter-name>setCharactor</filter-name>
  34. <url-pattern>/*</url-pattern>
  35. </filter-mapping>
  36. <!-- struts拦截器 -->
  37. <filter>
  38. <filter-name>struts2</filter-name>
  39. <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  40. </filter>
  41. <filter-mapping>
  42. <filter-name>struts2</filter-name>
  43. <url-pattern>*.do</url-pattern>
  44. <url-pattern>*.jsp</url-pattern>
  45. <dispatcher>FORWARD</dispatcher>
  46. <dispatcher>REQUEST</dispatcher>
  47. <dispatcher>INCLUDE </dispatcher>
  48. </filter-mapping>
  49. <!-- spring -->
  50. <context-param>
  51. <param-name>contextConfigLocation</param-name>
  52. <param-value>
  53. /WEB-INF/classes/applicationContext.xml
  54. </param-value>
  55. </context-param>
  56. <!-- ########## 监听器 ########## -->
  57. <!-- spring监听器 -->
  58. <listener>
  59. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  60. </listener>
  61. </web-app>
四、在bo包建立User实体类及其Hibernate映射文件

User.java

  1. package com.suo.bo;
  2. /**
  3. * User entity. @author MyEclipse Persistence Tools
  4. */
  5. public class User implements java.io.Serializable {
  6. // Fields
  7. private Integer id;
  8. private String name;
  9. private String password;
  10. private String email;
  11. private String address;
  12. // Property accessors
  13. public Integer getId() {
  14. return this.id;
  15. }
  16. public void setId(Integer id) {
  17. this.id = id;
  18. }
  19. public String getName() {
  20. return this.name;
  21. }
  22. public void setName(String name) {
  23. this.name = name;
  24. }
  25. public String getPassword() {
  26. return this.password;
  27. }
  28. public void setPassword(String password) {
  29. this.password = password;
  30. }
  31. public String getEmail() {
  32. return this.email;
  33. }
  34. public void setEmail(String email) {
  35. this.email = email;
  36. }
  37. public String getAddress() {
  38. return this.address;
  39. }
  40. public void setAddress(String address) {
  41. this.address = address
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/185257
推荐阅读
相关标签
  

闽ICP备14008679号