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. 序列化框架MJExtension详解 + iOS ORM框架

    当开发中你的模型中属性名称和 字典(JSON/XML) 中的key 不能一一对应时, 或者当字典中嵌套了多层字典数组时..., 以及教你如何用 MJExtension 配置类来统一管理你的模型配置, ...

  2. Linux之解决每次git pull/git push都需输入密码设置

    操作命令: //执行这两条命令cd / git config --global credential.helper store 执行完命令之后会在.gitconfig文件中多加红色字体 [user] ...

  3. 436. Find Right Interval

    Given a set of intervals, for each of the interval i, check if there exists an interval j whose star ...

  4. HDU4801【DFS】

    参考:大牛博客 题意:  给你一个2阶魔方,给你24个数代表颜色,然后让你求在<=n次操作里面最多能搞出几面是一样的. 思路: 就是一个DFS嘛,就是怎么转搞出来: 上面: 22 23 4 0 ...

  5. Bloomberg Desktop Api 关于历史Tick数据的一些参考

    使用WAPI命令可以看到当前BBG的Api情况. 目前2016年3月是V3的版本.其中有一个API Develper's Guide 中有Core Develper Guide的pdf, 里面提到了B ...

  6. IT兄弟连 JavaWeb教程 EL与JSTL表达式经典面试题

    1.简述EL表达式的作用 EL表达式的作用可分为以下三类 访问Bean的属性. 输出简单的运算结果. 获取请求参数值. 2.JSP标签的作用?如何定义? JSP标签可以分离JSP页面的内容和逻辑,业务 ...

  7. Django框架的安装,项目创建

    目录 Django框架的安装,项目创建 方法安装 Django版本选择 1.11.21(最新LTS版) django管理目录 命令行创建项目 django项目 命令行启动 (必须在项目文件下执行) p ...

  8. StretchDIBits速度测试(HALFTONE)

    StretchDIBits速度测试(HALFTONE) 下面实验中显示窗口大小为1024*768,拉伸模式设为HALFTONE. 一.单通道图像 (1) 保持图像高度为1024,宽度从24到2024递 ...

  9. Java集合框架常见面试题

    点击关注公众号及时获取笔主最新更新文章,并可免费领取本文档配套的<Java面试突击>以及Java工程师必备学习资源. 剖析面试最常见问题之Java基础知识 说说List,Set,Map三者 ...

  10. drupal中文安装指导

    (注:drupal6中文包放在profiles/default/translations下,drupal7放在profiles/standard/translations下) Drupal 6 中文安 ...