• DWR Annotations


    DWR   Annotations

    DWR 标注是用来代替 dwr.xml 或者与其一同工作的。

    1.初始配置

     1 <servlet>
     2     <description>DWR controller servlet</description>
     3     <servlet-name>DWR controller servlet</servlet-name>
     4     <servlet-class>
     5         org.directwebremoting.servlet.DwrServlet
     6     </servlet-class>
     7     <init-param>
     8         <param-name>classes</param-name>
     9         <param-value>
    10             com.example.RemoteFunctions, com.example.RemoteBean
    11         </param-value>
    12     </init-param>
    13 </servlet>    

      servlet 参数 classes 定义的时可以标注的类的全名,这些名字用逗号分割。

    2.远程访问类

      要使一个简单的 class 可以成为远程访问类,你需要使用@Create 和@RemoteMethod 标注。

    1 @Create
    2 public class RemoteFunctions {
    3     @RemoteMethod
    4     public int calculateFoo() {
    5         return 42;
    6     }
    7 }

      没有被@RemoteMethod 标注的方法不能被远程访问。

      要在 Javascript 使用不同于类型的名字,使用@Create 标注的 name 属性。

    @Create(name = "Functions")
    public class RemoteFunctions { 
    }

    3.对象转换

      要使一个简单的 bean 类可以被远程访问,  使用@Convert 和@RemoteProperty 标注:

     1 @Convert
     2 public class Foo {
     3 
     4     @RemoteProperty
     5     private int foo;
     6 
     7     public int getFoo() {
     8         return foo;
     9     }
    10 
    11     @RemoteProperty
    12     public int getBar() {
    13         return foo * 42;
    14     }
    15 }

      要使用复杂的转换器,使用@Convert 标注的  converter  属性。

    错误和异常处理

      

    走在一起是缘分,在一起走是幸福; 在一起走是缘分,走在一起是幸福
  • 相关阅读:
    数组(Array)
    js数据类型自动转化规律
    ES6-12.Symbol
    彻底搞懂prototype和__proto__
    API测试利器——Postman(1. 安装和启动)
    全国各城市的代码邮编sql(mysql版)
    SQL执行的顺序
    jQuery $.each用法
    使用maven工具对maven项目进行打包所出现的问题
    关于Notepad++中用正则表达式匹配中文的问题
  • 原文地址:https://www.cnblogs.com/tarena/p/3684146.html
Copyright © 2020-2023  润新知