1.所需要的JAR包

2.web.xml配置文件,这个和平时的配置是一样的

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
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_2_5.xsd"> <!-- spring -->
<context-param>
<param-name>springConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<!-- contentloader -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <!-- struts -->
<filter>
<filter-name>struts</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter>
<filter-name>struts-cleanup</filter-name>
<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
</filter> <filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>*.do</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping> <filter-mapping>
<filter-name>struts-cleanup</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

3.applicationContex.xml文件配置,sessionFactory的配置类是:org.springframework.orm.hibernate4.LocalSessionFactoryBean

<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<!-- onload hibernate.properties file -->
<bean id="propertyConfig"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>/WEB-INF/jdbc.properties</value>
</property>
</bean> <!--c3p0 连接池-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass">
<value>${hibernate.connection.driver_class}</value>
</property>
<property name="jdbcUrl">
<value>${hibernate.connection.url}</value>
</property>
<property name="user">
<value>${hibernate.connection.username}</value>
</property>
<property name="password">
<value>${hibernate.connection.password}</value>
</property> <!-- 连接池中保留的最小连接数. -->
<property name="minPoolSize">
<value>5</value>
</property>
<!-- 连接池中保留的最大连接数。Default: 15 -->
<property name="maxPoolSize">
<value>100</value>
</property>
<!-- 初始化时获得的连接数,取值应在minPoolSize与maxPoolSize之间。Default: 3 -->
<property name="initialPoolSize">
<value>5</value>
</property>
<!-- 最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->
<property name="maxIdleTime">
<value>60</value>
</property>
<!-- 当连接池中的连接耗尽的时候c3p0一次同时获得的连接数。Default: 3 -->
<property name="acquireIncrement">
<value>3</value>
</property>
</bean> <!--create sessionFactory-->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<!-- config hibernate Field -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect"> ${hibernate.dialect}</prop>
<prop key="hibernate.generate_statistics">true</prop>
<prop key="hibernate.jdbc.fetch_size"> ${hibernate.jdbc.fetch_size}</prop>
<prop key="hibernate.jdbc.batch_size"> ${hibernate.jdbc.batch_size}</prop>
<prop key="hibernate.current_session_context_class">thread</prop>
<prop key="hibernate.bytecode.use_reflection_optimizer">false</prop>
<prop key="hibernate.query.substitutions">true</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.max_fetch_depth">3</prop>
<prop key="hibernate.hibernate.use_outer_join">true</prop>
<prop key="hibernate.jdbc.batch_size">50</prop>
</props>
</property>
<!--mapping hibernate model po class-->
<property name="mappingDirectoryLocations">
<list>
<value>/WEB-INF/classes/com/fit/core/pojo</value>
</list>
</property>
</bean> <!--config transaction manager-->
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean> <bean id="basedao" class="com.fit.core.dao.impl.BaseDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="basebean" class="com.fit.core.bean.impl.BaseBeanImpl">
<property name="basedao" ref="basedao"></property>
</bean> </beans>

4.jdbc.properties配置文件

  

5.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="default" extends="struts-default">
<action name="findUserList" class = "com.fit.core.action.UserAction" method="findUserList">
<result name="success">/WEB-INF/jsp/list.jsp</result>
</action>
</package>
</struts>

6.Daoimp.java

package com.fit.core.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory; import com.fit.core.dao.BaseDao; public class BaseDaoImpl implements BaseDao {
private SessionFactory sessionFactory; public SessionFactory getSessionFactory() {
return sessionFactory;
} public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
} public boolean deleteObject(Object object) {
boolean flag = false;
try{
Session session = sessionFactory.openSession();
session.delete(object);
flag = true;
}catch(Exception e ){
e.printStackTrace();
}
return flag;
} public Object findObject(Class c, int id) {
boolean flag = false;
try{
Session session = sessionFactory.openSession();
session.get(c, id);
flag = true;
}catch(Exception e ){
e.printStackTrace();
}
return flag;
} public List listQuery(String hql) {
// TODO Auto-generated method stub
List list = null ;
try{
Session session = sessionFactory.openSession();
list = session.createQuery(hql).list();
}catch(Exception e){
e.printStackTrace();
}
return list;
} public boolean save(Object obj) {
boolean flag = false;
try{
Session session = sessionFactory.openSession();
session.save(obj);
flag = true;
}catch(Exception e ){
e.printStackTrace();
}
return flag;
} public boolean updateObject(Object obj) {
boolean flag = false;
try{
Session session = sessionFactory.openSession();
session.update(obj);
flag = true;
}catch(Exception e ){
e.printStackTrace();
}
return flag;
} public boolean updateObject(String hql) {
boolean flag = false;
Session session = sessionFactory.openSession();
Query query = session.createQuery(hql);
if(query != null){
int a = query.executeUpdate();
if(a > 0){
flag = true;
session.getTransaction().commit();//提交事物
}
}
return flag;
} }

  

  

hibernate4+spring3+struts2搭建框架实例的更多相关文章

  1. Struts2验证框架实例

    今天写了个Struts验证框架的实例,总算把验证框架弄清楚了. 上一篇Struts实例的action没有继承ActionSupport类,虽然也可以实现action的功能,但是却不能应用Struts提 ...

  2. SpringMVC笔记——SSM框架搭建简单实例

    落叶枫桥 博客园 首页 新随笔 联系 订阅 管理 SpringMVC笔记——SSM框架搭建简单实例 简介 Spring+SpringMVC+MyBatis框架(SSM)是比较热门的中小型企业级项目开发 ...

  3. 基于Docker的TensorFlow机器学习框架搭建和实例源码解读

    概述:基于Docker的TensorFlow机器学习框架搭建和实例源码解读,TensorFlow作为最火热的机器学习框架之一,Docker是的容器,可以很好的结合起来,为机器学习或者科研人员提供便捷的 ...

  4. 【转】SpringMVC+Spring3+Hibernate4开发环境搭建

    原文地址: SpringMVC+Spring3+Hibernate4开发环境搭建

  5. (六)Spring4 整合Hibernate4,Struts2

    第一节:S2SH 整合所需Jar 包 Struts2.3.16,Spring4.0.6,Hibernate4.3.5 整合所需jar 包: Struts2.3.16 jar 包 Spring4.0.6 ...

  6. Struts2漏洞利用实例

    Struts2漏洞利用实例 如果存在struts2漏洞的站,administrator权限,但是无法加管理组,内网,shell访问500. 1.struts2 漏洞原理:struts2是一个框架,他在 ...

  7. 初学springMVC搭建框架过程及碰到的问题

    刚刚开始学spring框架,因为接了一个网站的项目,想用spring+springMVC+hibernate整合来实现它,现在写下搭建框架的过程及碰到的问题.希望给自己看到也能让大家看到不要踏坑. 一 ...

  8. spring+struts2+ibatis 框架整合以及解析

    一. spring+struts2+ibatis 框架 搭建教程 参考:http://biancheng.dnbcw.net/linux/394565.html 二.分层 1.dao: 数据访问层(增 ...

  9. 【python3+request】python3+requests接口自动化测试框架实例详解教程

    转自:https://my.oschina.net/u/3041656/blog/820023 [python3+request]python3+requests接口自动化测试框架实例详解教程 前段时 ...

随机推荐

  1. 算法学习--Day4

    今天写了两章题目,仍然是比较基础的内容.感觉时间好紧张,怕来不及,所以以后要加快速度了. 今天写的最多的是查找类题目,关键是二分查找的掌握. 题目描述 输入一个数n,然后输入n个数值各不相同,再输入一 ...

  2. hihocoder #1335 : Email Merge(map+sort)

    传送门 题意 分析 每次插入人名与邮箱的时候,做一次并查集,然后做一次sort即可 trick 3 a 1 first@hihocoder.com b 1 second@hihocoder.com c ...

  3. POJ3020【二分匹配】

    思路: ---说给自己 一开始想的是从1-h*w标记整幅图,建图是星号和 {他,与他相连的星号} 建边,肯定要去匹配"*"啊,所以空格一定不会去造,然后就理解成了最小点覆盖,然而对 ...

  4. String字符串操作题

    /** * 反转键盘录入字符串 * 反转键盘录入的字符串 * 反转键盘录入的字符串 * 反转键盘录入的字符串 * */ Scanner sc = new Scanner(System.in);Stri ...

  5. java模拟进程调度之模拟抢占试多级轮转调度(附带可视化解决方案)

    1.简介一下多级轮转调度 多级轮转调度是一种提高调度效率的解决方案,简单讲就是讲要执行的程分成几个优先级的列队即例如三个,第一个列队分10个时间片,第二个列队分配1000个时间片,第三个列队表示100 ...

  6. 关于在linux系统环境下解压rar压缩文件

    如果在zip压缩文件,可以使有unzip来进行解压.可以直接使用yum进行下载. 但如果是rar类型压缩文件,使用yum就可能无法直接安装. 要到网址:https://www.rarlab.com/d ...

  7. endless(2018.10.25)

    这题就是个线段树合并板子. #include<cstdio> #include<algorithm> #include<cstring> using namespa ...

  8. PostgreSQL - 用psql 运行SQL文件

    对于预先写好的SQL文件,比如/home/user1/updateMyData.sql, 可以有两种方式来运行这个SQL文件. 方式一:连接db后执行SQL文件 首先通过psql连接到对应的db: p ...

  9. python 函数求两个数的最大公约数和最小公倍数

    1. 求最小公倍数的算法: 最小公倍数  =  两个整数的乘积 /  最大公约数 所以我们首先要求出两个整数的最大公约数, 求两个数的最大公约数思路如下: 2. 求最大公约数算法: 1. 整数A对整数 ...

  10. [题解](约数)BZOJ_1053_反素数

    三条引理:1.1~N中最大风反质数,就是1~N中约数个数最多的最小的一个 比较显然,是应该看出来的一条 2.1~N中任何数的不同因子都不会超过10个,且所有质因子的指数之和不超过30: 2*3*5*7 ...