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. Lightoj 1067【逆元模板(求C(N,M))】

    #include <bits/stdc++.h> using namespace std; typedef long long LL; typedef unsigned long long ...

  2. [Xcode 实际操作]二、视图与手势-(11)UITapGestureRecognizer手势之长按

    目录:[Swift]Xcode实际操作 本文将演示使用视图的长按手势,完成视图的交互功能. import UIKit class ViewController: UIViewController { ...

  3. IT兄弟连 JavaWeb教程 JSTL标签的使用

    假定甲方打算使用乙方开发的标签库,乙方把与标签库相关的所有文件打包成为了一个JAR文件(假定名为standard.jar),在这个JAR文件中包含以下内容: ●  标签处理类及相关的.class文件 ...

  4. maven - 安装目录详解

    从 Apache Maven 官网下载 Maven 的安装包并解压之后,进入安装目录,我们会看到如下内容: 接下来我们分别解读目录的内容及其功能 bin 包含了mvn运行的脚本,在命令行输入任意一条m ...

  5. wordcloud 的常规方法

    wordcloud 库把词云当作一个WordCloud对象 ——wordcloud.WordCloud() 代表一个文本对应的词云 ——可以根据文本中词语出现的频率等参数绘制词云 ——绘制词云的形状. ...

  6. Vuex目录结构推荐

    目录结构如下: - src - store // 在src目录下 新建一个store文件夹 - mutations.js // mutations - mutaions_types.js // mut ...

  7. 去掉UItalbeview横线

    一.去掉UItalbeview中所有横线 //    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; 二.自定义U ...

  8. css-原理详解

    语法 CSS 规则由两个主要的部分构成:选择器,以及一条或多条声明: 选择器一般使用id或者class选择器,声明由{}包含,每条声明由一个属性和一个值组成. .city { float:left; ...

  9. c/c++学习系列之取整函数,数据宽度与对齐

    浮点数的取整 C/C++取整函数ceil(),floor() double floor(double x); double ceil(double x); 使用floor函数.floor(x)返回的是 ...

  10. 安装linux时的分区问题,需要了解目录树及挂载知识

    Linux是目录树架构,如何结合目录树架构与磁盘内的数据→挂载. Linux先有目录,后有磁盘分区.数据(文件)依存于目录. 目录为挂载点,磁盘分区的数据放置在该目录下,进入该目录,就可以读取该分区. ...