您当前的位置: 首页 > 

杨林伟

暂无认证

  • 1浏览

    0关注

    3337博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

45dwr - DWR Annotations

杨林伟 发布时间:2019-04-29 15:53:25 ,浏览量:1

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

初始配置

要使用 DWR 的标注,你需要在 web.xml 中配置不同的 DWR 控制器。


	DWR controller servlet
	DWR controller servlet
	org.directwebremoting.servlet.DwrServlet
	
		classes
		com.example.RemoteFunctions, com.example.RemoteBean
	

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

远程访问类

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

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

没有被@RemoteMethod 标注的方法不能被远程访问。 要在 Javascript 使用不同于类型的名字,使用@Create 标注的 name 属性。

@Create(name = "Functions")
public class RemoteFunctions {
}
对象转换

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

@Convert
public class Foo {
	@RemoteProperty
	private int foo;
	
	public int getFoo() {
	return foo;
	}
	@RemoteProperty
	public int getBar() {
	return foo * 42;
	}
}

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

关注
打赏
1662376985
查看更多评论
立即登录/注册

微信扫码登录

0.1752s