`

Spring 与struts2 和Hibernate 4.0 + Dwr 注解解决方安

 
阅读更多

1. web.xml 注册文件

 

 

<!--
   author liuqing
   datetime 2011-12-11
-->
<?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">
    
   <filter>
	   <filter-name>OpenSessionInView</filter-name>
	   <filter-class>
		   org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
	   </filter-class>
   </filter>
   <filter-mapping>
	   <filter-name>OpenSessionInView</filter-name>
	   <url-pattern>/*</url-pattern>
   </filter-mapping>
   
   
    
    <!--struts2 Filter-->
    <filter>
        <filter-name>struts2Filter</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
        <!-- modify .action is .html -->
        <init-param>
        	<param-name>struts.action.extension</param-name>
        	<param-value>htmls</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>struts2Filter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <!-- dwr 与Spring Integrating -->
    <servlet>
		  <servlet-name>dwr</servlet-name>
		  <servlet-class>org.directwebremoting.spring.DwrSpringServlet</servlet-class>
		  <init-param>
		    <param-name>debug</param-name>
		    <param-value>true</param-value>
		  </init-param>
    </servlet>
	<servlet-mapping>
	  <servlet-name>dwr</servlet-name>
	  <url-pattern>/dwr/*</url-pattern>
	</servlet-mapping>
    
	
    <!--Spring Listenter-->
    <!--context-param>
        <param-name>contextClass</param-name>
        <param-value>
          org.springframework.web.context.support.AnnotationConfigWebApplicationContext
        </param-value>
    </context-param-->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
               classpath:com/zk/website/conf/applicationContext.xml
        </param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <listener>
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>
    
    <!-- loading TableColumn Information -->
    <listener>
    	<listener-class>com.zk.website.listener.TableColumnNameListener</listener-class>
    </listener>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>default.jsp</welcome-file>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>
</web-app>

 

配置spring 配置文件

 

<?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:dwr="http://www.directwebremoting.org/schema/spring-dwr"
	 xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
         http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
         http://www.springframework.org/schema/context
         http://www.springframework.org/schema/context/spring-context-3.0.xsd
         http://www.directwebremoting.org/schema/spring-dwr
    http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd"
	xmlns:tx="http://www.springframework.org/schema/tx">

	<bean id="propertyConfigurer"
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<!--property name="location" value="classpath:jdbc.properties" /-->
		<property name="locations">
		    <list>
		        <value>classpath:jdbc.properties</value>
		        <value>classpath:hibernate.properties</value>
		    </list>
		</property>
	</bean>

	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<property name="driverClass" value="${jdbc.driverClassName}" />
		<property name="jdbcUrl" value="${jdbc.url}" />
		<property name="user" value="${jdbc.username}" />
		<property name="password" value="${jdbc.password}" />
	</bean>

	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="hibernateProperties">
	        <props>
	            <prop key="hibernate.dialect">${hibernate.dialect}</prop>
	            <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
	            <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
	            <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
	        </props>
        </property>
		<property name="packagesToScan" value="com.zk.website.domain" />
	</bean>

	<context:component-scan base-package="com.zk.website" />
	<context:annotation-config />
	<!-- 配置DWR 对象 -->
	<dwr:annotation-scan scanDataTransferObject="true" scanRemoteProxy="true" base-package="com.zk.website.dwr"/>
	<!-- 用配置文件的方法 -->
	<!--dwr:configuration>
		<dwr:convert type="bean" class="com.zk.website.dwr.Student"></dwr:convert>
	</dwr:configuration-->
	<dwr:controller id="dwrController" debug="true"></dwr:controller>

</beans>

 

配置文件hibernate.properties

 

hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.show_sql=true
hibernate.format_sql=true
hibernate.hbm2ddl.auto=update

 

jdbc.properties

 

jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/website
jdbc.username=root
jdbc.password=123456

 

 

 

 

 

3. hibernate 类文件

 

 

package com.zk.website.domain;


import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;


/**
 * 
 * @author liuqing
 * @see 
 * @version 1.0
 * 2011-12-11
 */
@Entity
@Table(name="consultingType")
public class ConsultingType  implements java.io.Serializable {


	private static final long serialVersionUID = -1841212339564306628L;
	
	 private Integer id;
     private String name;
     private Set<ProductConsulting> productConsultings = new HashSet<ProductConsulting>(0);

    public ConsultingType() {
    }
   
    @Id @GeneratedValue(strategy=IDENTITY)
    @Column(name="id", unique=true, nullable=false)
    public Integer getId() {
        return this.id;
    }
    
    public void setId(Integer id) {
        this.id = id;
    }
    
    @Column(name="name")
    public String getName() {
        return this.name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="consultingType")
    public Set<ProductConsulting> getProductConsultings() {
        return productConsultings;
    }

    public void setProductConsultings(Set<ProductConsulting> productConsultings) {
        this.productConsultings = productConsultings;
    }



}

 

 

hibentate 2)

   package com.zk.website.domain;

import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;


/**
 * 
 * @author liuqing
 * @see
 * @version 1.0
 * 2011-12-11
 */
@Entity
@Table(name="coporationInfoType")
public class CoporationInfoType  implements java.io.Serializable {

	private static final long serialVersionUID = 5576757129051664373L;
	 
	 private Integer id;
     private String name;
     private String remark;
     private Set<CoporationInfo> coporationInfoes = new HashSet<CoporationInfo>(0);

    public CoporationInfoType() {
    }

    @Id @GeneratedValue(strategy=IDENTITY)
    @Column(name="id", unique=true, nullable=false)
    public Integer getId() {
        return this.id;
    }
    
    public void setId(Integer id) {
        this.id = id;
    }
    
    @Column(name="name")
    public String getName() {
        return this.name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    @Column(name="remark")
    public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="coporationInfoType")
    public Set<CoporationInfo> getCoporationInfoes() {
        return coporationInfoes;
    }

    public void setCoporationInfoes(Set<CoporationInfo> coporationInfoes) {
        this.coporationInfoes = coporationInfoes;
    }

}

 

struts2类文件

 

   package com.zk.website.web;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;

/**
 * 
 * @author liuqing
 * @see 公司信息
 * @version 1.0
 * 2011-12-8
 */
@Controller("coporationInfoAction")
@Scope("prototype")
public class CoporationInfoAction extends ActionSupport {
	
	private static final long serialVersionUID = 3048607397328082554L;
	
	public String coporationInfo() {
		return SUCCESS;
	}

}
 

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">

<!-- START SNIPPET: xworkSample -->
<struts>
    <constant name="struts.i18n.reload" value="false" />
    <constant name="struts.devMode" value="true" />
    
    <package name="global" namespace="/" extends="struts-default">
    	<action name="index" class="indexAction">
    		<result name="success">/index.jsp</result>
    	</action>
    	<action name="" class="indexAction">
    		<result name="success">/index.jsp</result>
    	</action>
    </package>
    
    <package name="test_1" namespace="/helloWorld" extends="global">
        <action name="testAction" class="testAction" method="add">
            <result name="list">/testAction/test.jsp</result>
        </action>
    </package>
    <package name="product_1" namespace="/productInfo" extends="global">
    	<action name="productInfoAction_*" class="productInfoAction" method="{1}">
    	    <result name="success">/productInfo/productInfo_list.jsp</result>
    	</action>
    </package>
    
    <package name="customer_1" namespace="/customerServer" extends="global">
    	<action name="customerServerAction_*" class="customerServerAction" method="{1}">
    		<result name="success">/customerServer/customerServer_list.jsp</result>
    	</action>
    </package>
    
    <package name="findPeople_1" namespace="/findPeople" extends="global">
    	<action name="findPeopleAction_*" class="findPeopleAction" method="{1}">
    		<result name="success">/findPeople/findPeople_list.jsp</result>
    	</action>
    </package>
    
</struts>

 

dwr 类文件

 

package com.zk.website.dwr;

import java.util.ArrayList;
import java.util.List;

import org.directwebremoting.annotations.RemoteMethod;
import org.directwebremoting.annotations.RemoteProperty;
import org.directwebremoting.annotations.RemoteProxy;

/**
 * 
 * @author liuqing
 * @see
 * @version 1.0
 * 2011-12-11
 */
@RemoteProxy
public class DwrTest {
	
	public String test() {
		return "Hello World Dwr!";
	}
	//加了个这注象后没有加的默认不能访问
	@RemoteMethod
	public String usb() {
		return "usb";
	}
	@RemoteMethod
	public Student usbss() {
		Student stu = new Student();
		stu.setUsb("122431431");
		return stu;
	}
	@RemoteMethod
	public List<Student> queryByAll() {
		List<Student> students = new ArrayList<Student>();
		Student stu = new Student();
		stu.setUsb("122431431");
		Student stu1 = new Student();
		stu.setUsb("122431431");
		students.add(stu);
		students.add(stu1);
		return students;
	}
	
    protected String hellProtected() {
    	return "helloProtected";
    }
    
    private String priHello() {
    	return "private";
    }

} 

 

 

package com.zk.website.dwr;

import java.io.Serializable;

import org.directwebremoting.annotations.DataTransferObject;
import org.directwebremoting.annotations.RemoteProperty;

/**
 * 
 * @author liuqing
 * @see Dwr对象测试
 * @version 1.0
 * 2011-12-11
 */
@DataTransferObject
public class Student implements Serializable{
	
	
	private String usb;
	//同@RemoteMethod 一样
	@RemoteProperty
	private String id;

	public String getUsb() {
		return usb;
	}

	public void setUsb(String usb) {
		this.usb = usb;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
	
	
	
	

}
 

 

 

 

 

 

 

 OK 下面有整合后lib 包可以下载的报可以下载

 

希望对朋友们有所帮助

 

 

 

 

分享到:
评论

相关推荐

    OA办公自动化管理系统(Struts1.2+Hibernate3.0+Spring2+DWR)

    公文管理、申请审批、公告管理、会议管理、权限管理、个人办公、客户管理、人事等等。项目技术:Struts1.2 + Hibernate3.0 + Spring2 +DWR。java毕业设计 jsp毕业设计 ssh毕业设计

    Spring 2.0 + Struts 1.2 + Hibernate 3.2 + DWR 2.0 的JavaEE应用示例

    总结,该例示注释非常详细,演示Spring托管Hibernate和Struts的Action, 以及Spring的事务声明(包括1.x与2.x的用法)与非事务声明的使用方式。 使用DWR可以方便的使用Spring托管的持久层功能。 目的:希望广大Java...

    struts2+hibernate+spring+dwr整合

    Struts2、Hibernate、Spring 和 DWR 是四个在Java Web开发中非常重要的框架,它们各自在不同的领域提供了强大的功能,并且能够通过整合实现更高效、更灵活的应用开发。接下来,我们将详细探讨这些技术以及它们如何...

    struts2+spring+hibernate+dwr

    Struts2、Spring、Hibernate和DWR是Java Web开发中常用的四大框架,它们各自负责不同的功能,协同工作能构建出高效、灵活的企业级应用。在这个小实例中,开发者结合这四个框架来展示了一个完整的后端架构。 Struts2...

    Struts1.2+Hibernate3.0+Spring2+DWR OA 办公自动化管理系统

    本系统采用经典的SSH(Struts1.2、Hibernate3.0、Spring2)框架与DWR(Direct Web Remoting)技术进行构建,实现了后端与前端的高效交互。 **Struts1.2** 是一款基于MVC(Model-View-Controller)设计模式的Java ...

    Struts2 + spring + hibernate + dwr 完美整合代码

    Struts2、Spring、Hibernate和DWR是Java Web开发中常用的四大框架,它们各自负责不同的职责,协同工作可以构建出高效、稳定且易于维护的Web应用程序。本项目整合了这四大框架,实现了用户注册、多级下拉联动及表格...

    Struts2+Hibernate3+Spring2.5整合详细步骤+实例可运行代码

    1. word文档记录了Struts2+Hibernate3+Spring2.5整合详细步骤,附有操作步骤的图示参考,并给出了各个步骤的注意事项; 2. 源代码实例包括一个完整模块的增删改查操作,可直接运行,可以在此基础上直接进行自己系统...

    Struts2 + Spring + Hibernate + DWR 项目布署笔记

    通过以上步骤,我们可以构建一个集成了Struts2、Spring、Hibernate和DWR的高效Web应用,提供良好的用户交互和数据管理能力。这个框架组合在实际项目中广泛应用,但同时也需要开发者具备扎实的Java和Web开发基础,...

    spring+struts+hibernate+jbpm +dwr整合开发的OA办公系统源码

    这是一个基于Java技术栈,采用Spring、Struts、Hibernate、jbpm和DWR等多种框架整合开发的OA(Office Automation)办公系统源码项目。这个系统的构建旨在实现企业的日常办公自动化,提高工作效率,简化工作流程,...

    struts1+spring+hibernate+dwr 项目 满意度调查

    struts1+spring+hibernate+dwr 项目 满意度调查struts1+spring+hibernate+dwr 项目 满意度调查struts1+spring+hibernate+dwr 项目 满意度调查struts1+spring+hibernate+dwr 项目 满意度调查

    Spring+Struts2+Hibernate+DWR

    总结来说,"Spring+Struts2+Hibernate+DWR"是一个强大的Java Web开发组合,提供了模型、视图、控制器的完整解决方案,结合了优秀的依赖注入、事务管理、ORM和实时的前后端通信。理解并熟练掌握这一技术栈,对于Java...

    OA 办公自动化管理系统(Struts1.2+Hibernate3.0+Spring2+DWR)

    本系统基于Struts1.2、Hibernate3.0、Spring2和DWR四个核心技术框架构建,下面将详细介绍这些技术及其在OA系统中的应用。 **Struts1.2** 是一个开源的MVC(Model-View-Controller)框架,用于构建Java Web应用程序...

    struts2+hibernate+spring+dwr(用户注册)

    Struts2、Hibernate、Spring 和 DWR 是四个在 Java Web 开发中广泛应用的框架和技术,它们结合在一起可以构建高效、可维护的用户注册系统。以下是对这些技术的详细解释及其在用户注册中的应用: 1. **Struts2**:这...

    OA办公自动化管理系统(Struts1.2+Hibernate3.0+Spring2+DWR).zip

    OA办公自动化管理系统是一款基于Java技术的典型企业级应用,它采用了经典的SSH框架组合,即Struts1.2、Hibernate3.0和Spring2。这些框架是Java Web开发中的重要工具,帮助开发者构建高效、可维护的业务逻辑。下面将...

    ssh整合例子(spring3 + struts2 + hibernate4+dwr+ext+json)

    内含 ext+dwr+freemark+jasperreort+ireport+echance+oscache+velocite等技术 展示例子:http://zz563143188.iteye.com/blog/1462413 若要下载chm格式请到http://user.qzone.qq.com/563143188 程序源码下载地址10MB...

    struts1.2+hibernate3.2+spring2.5+dwr

    Struts1.2、Hibernate3.2、Spring2.5 和 DWR2.0 是一组经典的Java企业级开发框架组合,它们在Web应用程序开发中扮演着重要的角色。这些框架的集成为开发人员提供了强大的功能,使得后端数据管理、业务逻辑处理以及...

    spring3+struts2+hibernate3+dwr3+spring security3+ajax完整实例

    这是一个基于Java技术栈的Web应用实例,整合了Spring 3、Struts 2、Hibernate 3、Direct Web Remoting (DWR) 3、以及Spring Security 3,并且利用Ajax进行异步通信,实现了数据库配置的权限管理。下面将详细阐述这些...

    OA系统源码,采用Struts2.0+Hibernate+Spring架构外加DWR

    该源码成功整合了Struts2.0+Hibernate+Spring(SSH架构)+DWR+MySql+Tomcat,直接拷贝部署就可以运行,前提建立相应的数据库。模块包括(组织机构管理,人员管理,角色管理,权限管理等等),每个模块均有增删查改等...

Global site tag (gtag.js) - Google Analytics