项目文件夹结构例如以下:

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveW9uZ3poaWFu/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">

核心配置文件:

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">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <filter>
<filter-name>openSessionInViewFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>openSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <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>
</web-app>

applicationContext.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:context="http://www.springframework.org/schema/context"
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">
<!-- 用注解方式注入bean -->
<context:annotation-config />
<context:component-scan base-package="com.yza" /> <bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:config/jdbc.properties</value>
</list>
</property>
</bean> <!-- 数据库连接池 --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.drive}">
</property>
<property name="url" value="${jdbc.url}">
</property>
<property name="username" value="${jdbc.user}"></property>
<property name="password" value="${jdbc.password}"></property>
<property name="defaultAutoCommit" value="false"></property>
</bean> <!-- hibernate sessionFactory 创建 -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!--扫描包下的bean,不採用mapping开放性好-->
  <property name="packagesToScan">
<list>
<value>com.yza.model.</value> <!-- 注意最后的".", 会转换成"classpath*:com/xxx/entity/**/*.class" -->
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
</props>
</property>
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean> <!-- 这样的硬性写入太死。建议写一个主要的dao,再来继承,由于假设直接给HibernateDaoSupport或者不写都会报错
“sessionFactory' or 'hibernateTemplate' is required"
-->
<bean id="sysUserInfoDaoImpl" class="com.yza.sysuser.dao.SysUserInfoDaoImpl">
<property name="hibernateTemplate" ref="hibernateTemplate"></property>
</bean> <!-- 事物配置 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="find*" read-only="true" />
<tx:method name="add*" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut expression="execution(public * com.yza.service..*.*(..))"
id="myPointcut" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="myPointcut" />
</aop:config> </beans>

jdbc:

jdbc.drive=com.mysql.jdbc.Driver
jdbc.url=jdbc\:mysql\://10.6.0.56\:3306/jxproject? characterEncoding\=UTF-8&characterSetResults\=UTF-8&profileSQL\=true
jdbc.user=admins
jdbc.password=root

核心java代码

实体bean

/**
* @Project: ssh2
* @Title: SysUserInfo.java
* @Package com.yza.model
* @author yongzhian
* @date 2014-9-29 下午3:40:08
* @Copyright: 2014 www.yineng.com.cn Inc. All rights reserved.
* @version V1.0
*/
package com.yza.model; import javax.persistence.Column;
import javax.persistence.Entity;//一定要用这个包下的,不能是hibernate下的
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table; /**
* @ClassName SysUserInfo
* @Description 模块描写叙述
* @author yongzhian
* @Date 2014-9-29
*/
@Entity
@Table(name = "user_baseinfo", catalog = "commonuser")
public class SysUserInfo implements java.io.Serializable { /**
* serialVersionUID
*/
private static final long serialVersionUID = 1L; @Id
@Column(name = "info_id", unique = true, nullable = false)
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer userId; // 主键 @Column(name = "info_name")
private String infoName; // username @Column(name = "sex")
private String sex; // 性别 /**
* @return userId
*/
public Integer getUserId() {
return userId;
} /**
* @param userId 要设置的 userId
*/
public void setUserId(Integer userId) {
this.userId = userId;
} /**
* @return infoName
*/
public String getInfoName() {
return infoName;
} /**
* @param infoName 要设置的 infoName
*/
public void setInfoName(String infoName) {
this.infoName = infoName;
} /**
* @return sex
*/
public String getSex() {
return sex;
} /**
* @param sex 要设置的 sex
*/
public void setSex(String sex) {
this.sex = sex;
} }

action

/**
* @Project: ssh2
* @Title: SysuserAction.java
* @Package com.yza.sysuser.action
* @author yongzhian
* @date 2014-9-29 下午3:49:43
* @Copyright: 2014 www.yineng.com.cn Inc. All rights reserved.
* @version V1.0
*/
package com.yza.sysuser.action; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.apache.struts2.interceptor.ServletRequestAware; import com.opensymphony.xwork2.ActionSupport;
import com.yza.sysuser.dao.SysuserDao;
import com.yza.sysuser.service.SysuserService; /**
* @ClassName SysuserAction
* @Description 模块描写叙述
* @author yongzhian
* @Date 2014-9-29
*/
@ParentPackage("struts-default")
@Namespace("/sysuser")
@Results({
@Result(name = "success" , location = "/pages/userinfo.jsp"),
})
public class SysuserAction extends ActionSupport implements ServletRequestAware{ /**
* serialVersionUID
*/
private static final long serialVersionUID = 1L; @Resource
private SysuserService sysuserService; protected HttpServletRequest request; @Action("getUserInfo")
public String getUserInfo(){
String userIdStr = this.request.getParameter("userId");
if(userIdStr != null){
request.setAttribute("user", sysuserService.getSysUserInfo(Integer.parseInt(userIdStr))); }
request.setAttribute("tt", "12");
return "success"; } /* (non-Javadoc)
* <p>Title: setServletRequest</p>
* <p>Description: 方法描写叙述</p>
* @param request
* @see org.apache.struts2.interceptor.ServletRequestAware#setServletRequest(javax.servlet.http.HttpServletRequest)
*/
@Override
public void setServletRequest(HttpServletRequest request) {
this.request = request;
} }

service

/**
* @Project: ssh2
* @Title: SysuserDao.java
* @Package com.yza.sysuser.dao
* @author yongzhian
* @date 2014-9-29 下午4:19:27
* @Copyright: 2014 www.yineng.com.cn Inc. All rights reserved.
* @version V1.0
*/
package com.yza.sysuser.service; import com.yza.model.SysUserInfo; /**
* @ClassName SysuserDao
* @Description 模块描写叙述
* @author yongzhian
* @Date 2014-9-29
*/
public interface SysuserService { public SysUserInfo getSysUserInfo(Integer userId); }
/**
* @Project: ssh2
* @Title: SysuserServiceImpl.java
* @Package com.yza.sysuser.service
* @author yongzhian
* @date 2014-9-29 下午4:24:16
* @Copyright: 2014 www.yineng.com.cn Inc. All rights reserved.
* @version V1.0
*/
package com.yza.sysuser.service; import javax.annotation.Resource; import org.springframework.stereotype.Service; import com.yza.model.SysUserInfo;
import com.yza.sysuser.dao.SysuserDao; /**
* @ClassName SysuserServiceImpl
* @Description 模块描写叙述
* @author yongzhian
* @Date 2014-9-29
*/
@Service
public class SysuserServiceImpl implements SysuserService { @Resource
private SysuserDao sysuserDao;
/* (non-Javadoc)
* <p>Title: getSysUserInfo</p>
* <p>Description: 方法描写叙述</p>
* @param userId
* @return
* @see com.yza.sysuser.service.SysuserService#getSysUserInfo(java.lang.Integer)
*/
@Override
public SysUserInfo getSysUserInfo(Integer userId) {
return sysuserDao.getSysUserInfo(userId);
} }

dao

/**
* @Project: ssh2
* @Title: SysuserDao.java
* @Package com.yza.sysuser.dao
* @author yongzhian
* @date 2014-9-29 下午4:19:27
* @Copyright: 2014 www.yineng.com.cn Inc. All rights reserved.
* @version V1.0
*/
package com.yza.sysuser.dao; import com.yza.model.SysUserInfo; /**
* @ClassName SysuserDao
* @Description 模块描写叙述
* @author yongzhian
* @Date 2014-9-29
*/
public interface SysuserDao {
public SysUserInfo getSysUserInfo(Integer userId);
}
/**
* @Project: ssh2
* @Title: SysUserInfoDaoImpl.java
* @Package com.yza.sysuser.dao
* @author yongzhian
* @date 2014-9-29 下午4:21:16
* @Copyright: 2014 www.yineng.com.cn Inc. All rights reserved.
* @version V1.0
*/
package com.yza.sysuser.dao; import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository; import com.yza.model.SysUserInfo; /**
* @ClassName SysUserInfoDaoImpl
* @Description 模块描写叙述
* @author yongzhian
* @Date 2014-9-29
*/
@Repository
public class SysUserInfoDaoImpl extends HibernateDaoSupport implements SysuserDao{ /* (non-Javadoc)
* <p>Title: getSysUserInfo</p>
* <p>Description: 方法描写叙述</p>
* @param userId
* @return
* @see com.yza.sysuser.dao.SysuserDao#getSysUserInfo(java.lang.Integer)
*/
@Override
public SysUserInfo getSysUserInfo(Integer userId) {
return this.getHibernateTemplate().get(SysUserInfo.class, userId);
}
}

ssh2项目整合 struts2.1+hibernate3.3+spring3 基于hibernate注解和struts2注解的更多相关文章

  1. SSH:Struts2.2+Hibernate3.6+Spring3.1分页示例[转]

    参考资料 1 ssh分页(多个例子) http://useryouyou.iteye.com/blog/593954 2 ssh2分页例子 http://459104018-qq-com.iteye. ...

  2. SSH项目整合教学Eclipse搭建SSH(Struts2+Spring3+Hibernate3)

    这篇博文的目的 尝试搭建一个完整的SSH框架项目. 给以后的自己,也给别人一个参考. 读博文前应该注意: 本文提纲:本文通过一个用户注册的实例讲解SSH的整合.创建Struts项目,整合Hiberna ...

  3. Struts2.3.4.1+Spring3.2.3+Hibernate4.1.9整合

    java教程|Struts2.3.4.1+Spring3.2.3+Hibernate4.1.9整合教程并测试成功一.创建项目二.搭建struts-2.3.4.11.struts2必须的Jar包(放到W ...

  4. SSH2项目网上书店系统手把手教学_Struts2+Spring+Hibernate整合开发

    一 序言 鉴于目前J2EE的火热程度,SSH2是每个学生毕业前都必须掌握的一门技术,所以在这里我就使用SSH2技术做一个小型项目,和大家一起学习. SSH2技术的基础概论就不再提了,直接说特点吧. 1 ...

  5. Spring3 + Spring MVC+ Mybatis 3+Mysql 项目整合(注解及源码)

    Spring3 + Spring MVC+ Mybatis 3+Mysql 项目整合(注解及源码) 备注: 之前在Spring3 + Spring MVC+ Mybatis 3+Mysql 项目整合中 ...

  6. eclipse环境下基于已构建struts2项目整合spring+hibernate

    本文是基于已构建的struts2项目基础上整合 spring+hibernate,若读者还不熟悉struts2项目,请先阅读 eclipse环境下基于tomcat-7.0.82构建struts2项目 ...

  7. Struts2+Spring+Hibernate3整合

    这几天正在复习三大框架的知识,特意把写出来,如有错误,希望大家多指教! 代码地址:https://git.coding.net/puchenglin/SSHDemo.git 1. 引入jar包 Str ...

  8. Maven项目整合Struts2框架

    -------------------------siwuxie095                                 Maven 项目整合 Struts2 框架         1. ...

  9. MyEclipse搭建SSH(Struts2+Spring2+Hibernate3)框架项目教程

    对Struts.spring.hibernate大体上了解一遍后,就是针对这个几个框架的整合了. 怎样整合,请看以下: 第一:Struts2的jar和xml配置文件: jar包: commons-fi ...

随机推荐

  1. 利用eclipse调试JDK源码

    先看效果图 综合网上各种教程,总结如下 新建 D:/jdk/src .D:/jdk/debug 目录 src存放源码 debug存放编译结果 将 %JAVA_HOME%/src.zip 解压到 D:/ ...

  2. C++学习笔记(三)之函数库

    1.标准库函数 begin end begin 返回数组首地址 end   返回数组尾地址 2.const 在声明变量时对变量限制为只读,不允许修改 const int i = 5; 单个const作 ...

  3. table的数据行tr上下移动

    昨天帮别人解决一个前端页面表格里的数据行上下移动的前端效果,直奔google找了几个demo,发现demo是实现了效果,但是代码很多,最后还是决定自己用jquery写个吧, 首先将前端效果分析出编程逻 ...

  4. Vue.js——router-link阻止click事件

    router-link 只能单纯做路由跳转 https://segmentfault.com/q/1010000007896386

  5. jquery.ajax之beforeSend方法使用介绍

    常见的一种效果,在用ajax请求时,没有返回前会出现前出现一个转动的loading小图标或者“内容加载中..”,用来告知用户正在请求数据.这个就可以用beforeSend方法来实现. 下载demo:a ...

  6. 安卓app测试之内存监控

    一.通过Dumpsys 来取值 1.adb shell dumpsys meminfo 获取的所有进程的内存信息,以及总内存,剩余内存,使用的内存等信息. 2.想获得某一进程内存的详细信息,在后面加上 ...

  7. CAD得到0层上的所有实体(com接口VB语言)

    主要用到函数说明: IMxDrawSelectionSet::Select 构造选择集.详细说明如下: 参数 说明 [in] MCAD_McSelect Mode 构造选择集方式 [in] VARIA ...

  8. wpf mvvm模式下 在ViewModel关闭view

    本文只是博主用来记录笔记,误喷 使用到到了MVVM中消息通知功能 第一步:在需要关闭窗体中注册消息 public UserView() { this.DataContext = new UserVie ...

  9. Python 字符串常见的用法

    line = “ni hao wo jiao key” line.capotalize()#首字母大写 line.center(20)#居中显示固定的字符 line.count('n')#计数,计算该 ...

  10. PS切图基本操作

    PS切图基本操作 2016-05-11 20:56:46|  分类: PhotoShop|字号 订阅     下载LOFTER我的照片书  |     1首先在“文件”中打开一张图片.   2点击“移 ...