Struts2.0+Spring3+Hibernate3(SSH~Demo)

前言:整理一些集成框架,发现网上都是一些半成品,都是共享一部分出来(确实让人很纠结),这是整理了一份SSH的测试案例,完全可以用!

言归正传,首先强调一点首先,SSH不是一个框架,而是多个框架(struts+spring+hibernate)的集成,是目前较流行的一种Web应用程序开源集成框架,用于构建灵活、易于扩展的多层Web应用程序。

集成SSH框架的系统从职责上分为四层:表示层业务逻辑层数据持久层和域模块层,以帮助开发人员在短期内搭建结构清晰、可复用性好、维护方便的Web应用程序。其中使用Struts作为系统的整体基础架构,负责MVC的分离,在Struts框架的模型部分,控制业务跳转,利用Hibernate框架对持久层提供支持,Spring做管理,管理struts和hibernate。具体做法是:用面向对象的分析方法根据需求提出一些模型,将这些模型实现为基本的Java对象,然后编写基本的DAO(Data Access Objects)接口,并给出Hibernate的DAO实现,采用Hibernate架构实现的DAO类来实现Java类与数据库之间的转换和访问,最后由Spring做管理,管理struts和hibernate。

整个Demo的视图

下面是主要的代码模块

GenerateExcelAction.java

 

UpdateUserAction.java

User.hbm.xml

UserDAOImpl.java

UserDAO.java

下面是主要的配置文件

hibernate.cfg.xml

struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <package name="user" extends="struts-default"> <action name="saveUser" class="saveUserAction">
<result name="success" type="redirect">listUser.action</result>
<result name="input">/save.jsp</result>
</action>
<action name="listUser" class="listUserAction">
<result>/list.jsp</result>
</action>
<action name="deleteUser" class="removeUserAction">
<result name="success" type="redirect">listUser.action</result>
</action>
<action name="updatePUser" class="updatePUserAction">
<result name="success">/update.jsp</result>
</action>
<action name="updateUser" class="updateUserAction">
<result name="success" type="redirect">listUser.action</result>
<result name="input">/update.jsp</result>
</action> <action name="generateExcel" class="generateExcelAction">
<result name="success" type="stream">
<param name="contentType">application/vnd.ms-excel</param>
<param name="contentDisposition">filename="AllUsers.xls"</param>
<param name="inputName">downloadFile</param>
</result>
</action>
</package> </struts>

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost:3306/bkytest"></property>
<property name="username" value="root"></property>
<property name="password" value="123456"></property>
<property name="maxActive" value="100"></property>
<property name="maxIdle" value="30"></property>
<property name="maxWait" value="500"></property>
<property name="defaultAutoCommit" value="true"></property>
</bean> <!-- Bean Mapping 映射 -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/talent/example/user/bean/User.hbm.xml</value>
</list>
</property>
</bean> <bean id="userDao" class="com.talent.example.user.dao.impl.UserDAOImpl" scope="singleton">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean> <bean id="userService" class="com.talent.example.user.service.impl.UserServiceImpl">
<property name="userDao" ref="userDao"></property>
</bean> <bean id="saveUserAction" class="com.talent.example.user.action.SaveUserAction"
scope="prototype">
<property name="service" ref="userService"></property>
</bean> <bean id="listUserAction" class="com.talent.example.user.action.ListUserAction"
scope="prototype">
<property name="service" ref="userService"></property>
</bean> <bean id="removeUserAction" class="com.talent.example.user.action.RemoveUserAction"
scope="prototype">
<property name="service" ref="userService"></property>
</bean> <bean id="updatePUserAction" class="com.talent.example.user.action.UpdatePUserAction"
scope="prototype">
<property name="service" ref="userService"></property>
</bean> <bean id="updateUserAction" class="com.talent.example.user.action.UpdateUserAction"
scope="prototype">
<property name="service" ref="userService"></property>
</bean> <bean id="generateExcelAction" class="com.talent.example.user.action.GenerateExcelAction"
scope="singleton">
<property name="service" ref="userService"></property>
</bean>
</beans>

以及整个项目的Web.xml配置文件

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name>SSHv1.0</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml;</param-value>
</context-param> <filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter> <filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list> <listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener> </web-app>

以及简单的页面效果图

Demo下载地址:点击下载

 
分类: Java代码参考

Struts2.0+Spring3+Hibernate3(SSH~Demo)的更多相关文章

  1. SSH项目整合教学Eclipse搭建SSH(Struts2+Spring3+Hibernate3)

    这篇博文的目的 尝试搭建一个完整的SSH框架项目. 给以后的自己,也给别人一个参考. 读博文前应该注意: 本文提纲:本文通过一个用户注册的实例讲解SSH的整合.创建Struts项目,整合Hiberna ...

  2. 开发基础框架:mybatis-3.2.8 +hibernate4.0+spring3.0+struts2.3

    一:项目下载地址(点击 Source code(zip)) https://github.com/fzxblgong/frame_2014-12-15/releases 版本:v1.2大小:20M 二 ...

  3. struts2+spring3+hibernate3+mysql简单登录实现

    1.导入相关的jar包 2.建立数据库 1 create table account( 2 id int(10), 3 user varchar(50), 4 paw varchar(50) 5 ); ...

  4. Struts2.3+Spring3.2+Hibernate4.2框架搭建

    一.环境 SSH使用的版本:struts2.3.14.spring3.2.2.hibernate4.2.0 数据库:MYSQL tomcat版本:apache-tomcat-7.0.42 二.所需要导 ...

  5. BAE 环境下配置 struts2 + spring + hibernate(SSH)(三)spring&hibernate

    1.在lib中加入必要的包,导入后结果如下: lib打包下载:SSH-lib.jar  (struts2.3.1.2  spring3.0.5 hibernate3.6.10.Final) 只包含必要 ...

  6. Struts2+Hibernate+Spring(SSH)三大框架整合jar包

    Struts2 + Spring3 + Hibernate3 框架整合 1. 每个框架使用 (开发环境搭建 )* 表现层框架 struts2 1) jar包导入: apps/struts2_blank ...

  7. struts2、hibernate和SSH的实现

    Struts2 为什么开发Struts框架? 为了符合更加灵活.高效的开发需求 实质上Struts2是以WebWork为核心的,他采用拦截机制来处理用户请求. (1)Jsp部分 <%@ page ...

  8. 入门struts2.0

    框架是什么? 1.应用程序的半成品. 2.可重用行公共的结构. 3.按一定规则组织的一组组件. model2 其实并不是一种全新的概念,很对人指出model2其实正好是经典的"模型(mode ...

  9. struts2.0整合json

    框架:struts2.0+hibernate2+spring 今天写代码时,需要用到json,我就直接加了两个jar包:json-lib-2.1-jdk15.jar,struts2-json-plug ...

随机推荐

  1. IIS使用 URL Rewrite Module 2.0组件 设置伪静态的方法

    简体中文版WIn10无法安装,需要改注册表, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\InetStp  MajorVersion 项,这个也是 dword 值 10 ...

  2. C# HttpClient Cookie验证解决方法

    自实现的cookie 验证,远程取值的例子 以下代码配合HttpClient使用可以实现跨域(cookie的读写) //验证 复制代码 代码如下: HttpClient httpClient = ne ...

  3. 小代码编写神器:LINQPad 使用入门

    原文:小代码编写神器:LINQPad 使用入门 一:概述 1:想查看程序运行结果,又不想启动 VS 怎么办? 2:想测试下自己的 C# 能力,不使用 VS 的智能感知,怎么办? 那么,我们有一个选择, ...

  4. GitLab版本管理(转)

    GitLab是利用 Ruby on Rails 一个开源的版本管理系统,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目.它拥有与Github类似的功能,能够浏览源代码,管理 ...

  5. Codeforces 451E Devu and Flowers(容斥原理)

    题目链接:Codeforces 451E Devu and Flowers 题目大意:有n个花坛.要选s支花,每一个花坛有f[i]支花.同一个花坛的花颜色同样,不同花坛的花颜色不同,问说能够有多少种组 ...

  6. SDUT 2933-人活着系列Streetlights(最小生成树Kruskal+和理查德设置来实现)

    人活着系列之Streetlights Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描写叙述 人活着假设是为了家庭,亲情----能够说 ...

  7. Chapter 1 Securing Your Server and Network(10):使用扩展保护避免授权中继攻击

    原文:Chapter 1 Securing Your Server and Network(10):使用扩展保护避免授权中继攻击 原文出处:http://blog.csdn.net/dba_huang ...

  8. 恶意软件&quot;跨平台&quot; 小心钱包很受伤

    什么是跨平台攻击? 举例来说.就像网络诈骗犯为了避开电子商务平台的监控.会在微博上发消息.百度上撒网,腾讯上联系,最后在淘宝上交易.这样的跨平台操作的模式会大大添加犯罪过程监控和取证的难度.而跨平台攻 ...

  9. SynchronousQueue、LinkedBlockingQueue、ArrayBlockingQueue性能测试(转)

    听说JDK6对SynchronousQueue做了性能优化,避免对竞争资源加锁,所以想试试到底平时是选择SynchronousQueue还是其他BlockingQueue. 对于容器类在并发环境下的比 ...

  10. JAVA学习课第五十八届 — GUI

    GUI Graghical User Interface(图形用户接口) java为GUI提供的对象都存在java.awt和java.swing包中 Java的GUI做的的确干只是C++等.不打算浪费 ...