DWR3.0和Spring2.5的完美整合的應用開發

xiaoxiao2022-06-11  27

 

  在項目中開始使用DWR1.0發現DWR2.0有注解后,采用DWR2.0注解,但是遮增加了web.xml 中DWRServlet中classes參數的信息。終于DWR3.0發布了。采用DWR3.0開發實現完美整合。

DWR 3.0 RC1发布

DWR终于到达3.0版本,刚刚发布了3.0 release candidate 1。DWR(Direct Web Remoting)是一个WEB远程调用框架,能够在javascript直接调用java方法,而不必去写一大堆的javascript代码,利用这个框架可以让AJAX开发变得很简单. 新功能包括:提升RPC性能;提升字节文件上传/下载功能;通过JavaScript实现Java接口;提供可扩展的反向Ajax APIs;TIBCO GI集成;集成Dojo;支持更多的服务器比如Tomcat和Glassfish等等。 详情点击:DWR version 3.0 Release Candidate 1 点击这里下载DWR 3.0 RC1: http://directwebremoting.org/dwr/download

 

 

package com.unutrip.spring.dwr;

/** *  * @author longgangbai *  */public interface UserService { public String getUsername(UserVO user);

}

 

package com.unutrip.spring.dwr;

import org.directwebremoting.annotations.Param;import org.directwebremoting.annotations.RemoteMethod;import org.directwebremoting.annotations.RemoteProxy;import org.directwebremoting.spring.SpringCreator;import org.springframework.beans.factory.annotation.Autowired;

/** *  * @author longgangbai *  */@RemoteProxy(creator = SpringCreator.class, creatorParams = @Param(name = "beanName", value = "userServiceDWR"))public class UserServiceDWR { @Autowired private UserService userService;

 @RemoteMethod public String getUsername(UserVO user) {  return this.userService.getUsername(user); }

 public UserService getUserService() {  return userService; }

 public void setUserService(UserService userService) {  this.userService = userService; }}

 

package com.unutrip.spring.dwr;

import org.springframework.stereotype.Service;

/** *  * @author longgangbai *  */@Servicepublic class UserServiceImpl implements UserService {

 public String getUsername(UserVO user) {  return user.getUsername(); }

}

 

package com.unutrip.spring.dwr;

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

/** *  * @author longgangbai *  */@DataTransferObjectpublic class UserVO { @RemoteProperty private String username; @RemoteProperty private String password;

 public String getUsername() {  return username; }

 public void setUsername(String username) {  this.username = username; }

 public String getPassword() {  return password; }

 public void setPassword(String password) {  this.password = password; }

}

在applicationContext中配置如下:

 

<?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:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr"   xsi:schemaLocation="   http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd   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/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd   http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd   http://www.directwebremoting.org/schema/spring-dwr           http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd" default-autowire="byName">  <context:annotation-config/>   <context:component-scan base-package="com.unutrip.spring.dwr" /> <!-- order值越小, 优先级越高 -->      <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">          <property name="order" value="1" />      </bean>      <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping">          <property name="order" value="2" />      </bean>     <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">       <property name="prefix" value="/WEB-INF/jsp"></property>        <property name="suffix" value=".jsp"></property>    </bean></beans>

在action-servlet.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:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr"   xsi:schemaLocation="   http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd   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/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd   http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd   http://www.directwebremoting.org/schema/spring-dwr           http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd" default-autowire="byName"> <!--  <tx:annotation-driven/> -->     <!-- DWR --> <!--  New DWR capabilities--> <dwr:configuration>  <dwr:convert class="com.unutrip.spring.dwr.UserVO" type="bean" />  <dwr:signatures>   <![CDATA[    ]]>  </dwr:signatures> </dwr:configuration>  <dwr:annotation-config />  <dwr:url-mapping /> <!-- 部署项目时, 请把debug设为false -->      <dwr:controller id="dwrController" debug="true" />   

</beans>

 

註意點:添加了顔色哦!!哈哈哈

 

 

兩個查看開源源代碼的網站:

 

http://fisheye5.cenqua.com/browse/dwr/java/org/directwebremoting/dwrp/Batch.java?r=1.16#l109

 

http://www.java2s.com/Open-Source/Java-Document/Web-Services/spring-ws-1.0.0/org/springframework/oxm/AbstractMarshaller.java.htm

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

http://www.java2s.com/Code/JavaScript/CatalogJavaScript.htm

相关资源:谷歌安装器(如果Go安装器无法打卡可以使用这个)
转载请注明原文地址: https://www.6miu.com/read-4931161.html

最新回复(0)