ssh2项目整合 struts2.1+hibernate3.3+spring3 基于hibernate注解和struts2注解

项目目录结构如下:ssh2项目整合 struts2.1+hibernate3.3+spring3 基于hibernate注解和struts2注解_第1张图片

核心配置文件:

web.xml



	
		index.jsp
	
	
		contextConfigLocation
		classpath:applicationContext.xml
	
	
		org.springframework.web.context.ContextLoaderListener
	
	
	
		openSessionInViewFilter
		
			org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
		
	
	
		openSessionInViewFilter
		/*
	
	
	
		struts2
		
			org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
		
	
	
		struts2
		/*
	


applicationContext.xml



	
	
	

	
		
			
				classpath:config/jdbc.properties
			
		
	

	

	
		
		
		
		
		
		
		
	
	
	
	
		
               
                
			
				com.yza.model.
				
				 
			
		
		
			
				true
				update
				org.hibernate.dialect.MySQLDialect
			
		
	
	
		
	
	
	
	
		
	
	
	
	 

	
	
		
	
	
		
			
			
		
	
	
		
		
	


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; // 用户名
	
	@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)
	 * 

Title: setServletRequest

*

Description: 方法描述

* @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)
	 * 

Title: getSysUserInfo

*

Description: 方法描述

* @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)
	 * 

Title: getSysUserInfo

*

Description: 方法描述

* @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); } }



你可能感兴趣的:(开发框架-SSH)