整合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的仓库 本地仓库 远 ...
随机推荐
- LeetCode(Two Sum)
一.题目要求 Given an array of integers, return indices of the two numbers such that they add up to a spec ...
- 17、SpringBoot------整合dubbo
SpringBoot整合Dubbo+Zookeaper 1.安装运行zookeeper (1)下载zookeeper 官网:http://zookeeper.apache.org/ (2)解压缩 (3 ...
- JAVA_Converter_字符串类型转Date类型
我们知道数据库中的时间一般为Date类型,而前台传递过来的为字符串,BeanUtils在封装数据的时候,没有将类型转换,导致报异常... 我们只需要在封装数据之前,使用自定义转换器即可: 代码如下: ...
- C++声明之CV限定符
目录 1.const 1.1 const obj 如果调用 non-const member fun会编译出错 经典错误 1.2 例子:STD里的操作符重载 1.3 例子:<cpp primer ...
- BZOJ1509: [NOI2003]逃学的小孩(树的直径)
Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1126 Solved: 567[Submit][Status][Discuss] Description ...
- 【动态规划 floyd】SPOJ ACPC13
为什么rzz会把这题放在NOI模拟赛的T2? 题目大意 有一张$n$个点$m$条边的有向图,每条边有权值$w_i$. 定义一个任务$(a_i,b_i,c_i)$是如下一条路径: 最多经过$c_i$条边 ...
- 实例:关于ALV控件可编辑的整理
使ALV控件中的内容可编辑 这应该是一个非常有用的功能,这样我们便可以用它来代替table control来编出一些有这现成功能的界面来.实际上,让alv中的内容可以被编辑与alv的事件无关.但是经常 ...
- sql xml扩展字段 查询语句
[cms:sql query="SELECT ContentXML.value('/fields[1]/Address[1]','varchar(max)')AS valueForm FRO ...
- 【PHP】Maximum execution time of 30 seconds exceeded解决办法
Maximum execution time of 30 seconds exceeded,今天把这个错误的解决方案总结一下: 简单总结一下解决办法: 报错一:内存超限,具体报错语句忘了,简单说一下解 ...
- 【笔记】objdump命令的使用
---恢复内容开始--- objdump命令是Linux下的反汇编目标文件或者可执行文件的命令,它还有其他作用,下面以ELF格式可执行文件test为例详细介绍: objdump -f test 显示t ...