dwr annotation(DWR注解使用)

DWR Annotations

DWR annotations can be used as a replacement as well as in conjunction with dwr.xml.

Annotation support was written by Maik Schreiber.

Setup

To use DWR with annotations you need to specify a different DWR controller servlet in your web.xml:

<servlet>
  <description>DWR controller servlet</description>
  <servlet-name>DWR controller servlet</servlet-name>
  <servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
  <init-param>
    <param-name>classes</param-name>
    <param-value>
      com.example.RemoteFunctions,
      com.example.RemoteBean
    </param-value>
  </init-param>
</servlet>
 

The classes servlet parameter must provide a comma-separated list of the fully-qualified class names of all annotated classes to be used with DWR.

The syntax for inner classes is to use '$' notation (as used by Class.forName()) rather than '.' notation (as used by import statements). For example, use java.util.Map$Entry and not java.util.Map.Entry.

Remote Class Access

To make a simple class available for remote access, use the @Create and @RemoteMethod annotations:

@RemoteProxy
public class RemoteFunctions {
    @RemoteMethod
    public int calculateFoo() {
       return 42;
    }
}

Any method not annotated with @RemoteMethod will not be available for remote access.

To use a scripting name different from the class name, use the name attribute of @RemoteProxy:

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

Object Conversion

To make simple bean classes available for remote access, use the @DataTransferObject and @RemoteProperty annotations:

@DataTransferObject
public class Foo {
    @RemoteProperty
    private int foo;

    public int getFoo() {
        return foo;
    }

    @RemoteProperty
    public int getBar() {
        return foo * 42;
    }
}

To use more sophisticated converters see the converter attribute of the @DataTransferObject annotation.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值