整合S2SH框架
S2SH框架(Struts2,Spring,Hibernate)整合
Struts2、Hibernate和Spring。其中在Struts2部分主要为MVC设计思想,Struts2的处理流程及配置,Struts2常用控制器组件,以及Struts2常用标签库的使用。在Hibernate部分主要为O/R Mapping的设计理念,Hibernate对O/R Mapping的支持,Hibernate的配置及多种关系映射的实现,以及HQL查询数据。在Spring部分主要为IoC的原理,Spring对Bean的管理机制,Spring AOP编程,以及声明事务的配置和管理。
下面来配置一下SSH搭建环境:


首先配置Hibernate环境,参考我之前的博客:http://www.cnblogs.com/claricre/p/6509931.html
接下来就是要配置Struts环境,参考我的博客:http://www.cnblogs.com/claricre/p/6542757.html
然后是配置Spring,参考博客:http://www.cnblogs.com/claricre/p/6686231.html
整合流程就是上面三篇博客,下面贴出来整个配置环境:
NationAction.java:
package com.action;
import com.opensymphony.xwork2.ActionSupport;
public class NationAction extends ActionSupport {
public String show(){
return SUCCESS;
}
}
Nation.java实体类:
package com.model;
// Generated 2017-4-11 16:20:44 by Hibernate Tools 5.2.0.CR1 /**
* Nation generated by hbm2java
*/
public class Nation implements java.io.Serializable { private String code;
private String name; public Nation() {
} public Nation(String code) {
this.code = code;
} public Nation(String code, String name) {
this.code = code;
this.name = name;
} public String getCode() {
return this.code;
} public void setCode(String code) {
this.code = code;
} public String getName() {
return this.name;
} public void setName(String name) {
this.name = name;
} }
Nation.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Generated 2017-4-11 16:20:44 by Hibernate Tools 5.2.0.CR1 -->
<hibernate-mapping>
<class name="com.model.Nation" table="nation" catalog="mydb" optimistic-lock="version">
<id name="code" type="string">
<column name="Code" length="50" />
<generator class="assigned" />
</id>
<property name="name" type="string">
<column name="Name" length="50" />
</property>
</class>
</hibernate-mapping>
以上两个文件是通过Hibernate配置直接根据数据库表生成。
beans.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"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd"> <context:property-placeholder location="classpath:db.properties"/>
<bean class="com.mchange.v2.c3p0.ComboPooledDataSource" id="dataSource">
<property name="user" value="${user}"></property>
<property name="password" value="${password}"></property>
<property name="jdbcUrl" value="${jdbcUrl}"></property>
<property name="driverClass" value="${driverClass}"></property> <property name="minPoolSize" value="${minPoolSize}"></property>
<property name="maxPoolSize" value="${maxPoolSize}"></property>
</bean> <!-- hibernateTemplate --><!-- 如果需要可以引入hibernatTemolate来替代sessionFactory -->
<!-- <bean class="org.springframework.orm.hibernate5.HibernateTemplate" id="hibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean> -->
<!-- jdbcTemplate --><!-- 如果需要可以jdbcTemplate -->
<!-- <bean class="org.springframework.jdbc.core.JdbcTemplate" id="jdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean> --> <bean class="org.springframework.orm.hibernate5.LocalSessionFactoryBean" id="sessionFactory">
<property name="dataSource" ref="dataSource"></property>
<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
<property name="mappingLocations" value="classpath:com/model/*.hbm.xml"></property>
</bean> <bean class="org.springframework.orm.hibernate5.HibernateTransactionManager" id="transactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean> <!-- <tx:advice transaction-manager="transactionManager" id="txAdvice">
<tx:attributes>
<tx:method name="*"/>
</tx:attributes>
</tx:advice> <aop:config>
<aop:pointcut expression="execution(* com.model.*.*(..))" id="pointCut"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="pointCut"/>
</aop:config> --> </beans>
db.properties:
driverClass=com.mysql.jdbc.Driver
jdbcUrl=jdbc:mysql://localhost:3306/mydb
user=root
password=
minPoolSize=5
maxPoolSize=20
initialPoolSize=5
hibernate.cfg.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/mydb?characterEncoding=GBK</property>
<property name="hibernate.connection.username">root</property> -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property> <!-- <mapping resource="com/model/Nation.hbm.xml"/> -->
</session-factory>
</hibernate-configuration>
struts.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="true" /> <package name="default" namespace="" extends="struts-default"> <action name="*_*" class="com.action.{1}Action" method="{2}">
<result>
{1}/{2}.jsp
</result>
</action>
</package> </struts>
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list> <display-name>Struts Blank</display-name> <context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:beans.xml</param-value>
</context-param> <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter> <filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list> </web-app>
在页面中直接跑http://localhost:8080/SSH_zhenghe/Nation_show即可调出show.jsp页面的内容来了。
整合S2SH框架的更多相关文章
- S2SH框架的集成
S2SH框架的集成 20131130 代码下载 : 链接: http://pan.baidu.com/s/1sz6cQ 密码: 513t 这一个星期的时间里,学习SSH框架技术,首先因为之前的项目用到 ...
- 【Spring】Spring系列7之Spring整合MVC框架
7.Spring整合MVC框架 7.1.web环境中使用Spring 7.2.整合MVC框架 目标:使用Spring管理MVC的Action.Controller 最佳实践参考:http://www. ...
- Springmvc整合tiles框架简单入门示例(maven)
Springmvc整合tiles框架简单入门示例(maven) 本教程基于Springmvc,spring mvc和maven怎么弄就不具体说了,这边就只简单说tiles框架的整合. 先贴上源码(免积 ...
- SpringMVC整合Tiles框架
SpringMVC整合Tiles框架 Tiles组件 tiles-iconfig.xml Tiles是一个JSP布局框架. Tiles框架为创建Web页面提供了一种模板机制,它能将网页的布局和内容分离 ...
- Yii框架学习笔记(二)将html前端模板整合到框架中
选择Yii 2.0版本框架的7个理由 http://blog.chedushi.com/archives/8988 刚接触Yii谈一下对Yii框架的看法和感受 http://bbs.csdn.net/ ...
- 整合MVVM框架(Prism)
整合MVVM框架(Prism) 我们基础的框架已经搭建起来了,现在整合MVVM框架Prism,在ViewModel做一些逻辑处理,真正把界面设计分离出来. 这样方便我们系统开发分工合作,同时提高系统可 ...
- shiro权限控制(一):shiro介绍以及整合SSM框架
shiro安全框架是目前为止作为登录注册最常用的框架,因为它十分的强大简单,提供了认证.授权.加密和会话管理等功能 . shiro能做什么? 认证:验证用户的身份 授权:对用户执行访问控制:判断用户是 ...
- Maven 整合 SSH 框架
前面的一系列文章中,我们总结了三大框架:Struts2,Hibernate,Spring 的基本知识.本篇就姑且尝试着使用 Maven 这个项目构建工具来将这三个框架整合一起.说到这里,如果有对 Ma ...
- Maven02——回顾、整合ssh框架、分模块开发、私服
1 回顾 1.1 Maven的好处 节省空间 对jar包做了统一管理 依赖管理 一键构建 可跨平台 应用在大型项目可提高开发效率 1.2 Maven安装部署配置 1.3 Maven的仓库 本地仓库 远 ...
随机推荐
- NPM 学习笔记整理
NPM 学习笔记整理 阅读 550,2017年06月04日 发布,来源:blog.ihoey.com 什么是 NPM npm 之于 Node ,就像 pip 之于 Python , gem 之于 Ru ...
- 用FileReader对象获取图片base64代码并预览
MDN中FileReader的详细介绍: https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader 用FileReader获取图片base ...
- hdu_5288_OO’s Sequence
OO has got a array A of size n ,defined a function f(l,r) represent the number of i (l<=i<=r) ...
- MySQL(mariadb)主从复制模式与复制过滤
在前一篇文章<mysql多实例与复制应用>中只对mysql的复制做了简单的介绍,本篇内容专门介绍一下mysql的复制. MySQL复制 mysql复制是指将主数据库的DDL和DML操作通过 ...
- Golang反射机制
Go反射机制:在编译不知道类型的情况下,可更新变量.在运行时查看值.调用方法以及直接对它们的布局进行操作. 为什么使用反射 有时需要封装统一接口对不同类型数据做处理,而这些类型可能无法共享同一个接口, ...
- Redis ---------- 持久化(AOF)操作
每小时做一次快照持久化 8:00 快照持久化 9:00 快照持久化 10:00 快照持久化 上帝想玩弄人类,突然停电,55万个key丢失了 11:00 快照持久化 解决方案: 8:00-9:00在 ...
- PHP下载远程文件到指定目录
PHP用curl可以轻松实现下载远程文件到指定目录: <?php class Download { public static function get($url, $file) { retur ...
- Python系列6之面向对象
目录 生成器和迭代器 字符串格式化 内置函数vars 反射 面向对象编程 一. 生成器和迭代器 1. 生成器 生成器具有一种生成的能力,它仅仅代表着一种生成的能力,当我们需要使用的时候,才会通过迭代 ...
- 为 vsftpd 启动 vsftpd:500 OOPS: SSL: cannot load RSA&nb
博主在配置ftp服务器的时候 自己生成的CA,然后认证自己的私钥文件 一切配置都是没有问题的,然后重新启动服务器 service vsftpd restart 出现以下错误 为 vsftpd 启 ...
- NPOI导出Excel,添加图片和设置格式,添加条形码
先上代码 using grproLib; using System; using System.Collections.Generic; using System.Data; using System ...