使用DWR,可以非常方便的将一个JS对象转变成一个JAVA对象,提供数据给后台进行处理。
下面是的官方网站例子:
Creating Javascript objects to match Java objects
Suppose you have an exposed Java method like this:
public class Remote {
public void setPerson(Person p) {
this.person = p;
}
}
And Person looks like this:
public Person {
private String name;
private int age;
private Date[] appointments;
// getters and setters ...
}
Then you can call this from Javascript like this:
var p = {
name:"Fred Bloggs",
age:42,
appointments:[ new Date(), new Date("1 Jan 2008") ]
};
Remote.setPerson(p);
Any fields missing from the Javascript representation will be left unset in the Java version.
Since the setter returned 'void' we did not need to use a callback and could just leave it out. If you want to be notified of the completion of a server-side method that returns void then you can include a callback method. Obviously DWR will not pass any data to it.
本文介绍如何使用DWR技术将JavaScript对象轻松转换为Java对象,并传递给后端进行处理。通过示例展示了创建匹配Java对象的JavaScript对象的方法。

2537

被折叠的 条评论
为什么被折叠?



