1. 在java类中,声明方法
@RemoteMethod
public ClassInfo getBean(){
ClassInfo entity = new ClassInfo();
entity.setId(EnvUtils.getHashId());
return entity;
}
2.在dwr.xml配置中声明方法返回的值为javabean
<dwr>
<allow>
<!-- javascript对应页面中引入的js文件名称 -->
<create creator="new" javascript="hello">
<!-- <param>标签指定要公开给javascript的java类名。
<include>标签指定要公开给javascript的方法。不指定的话就公开所有方法。
<exclude>标签指定要防止被访问的方法。 -->
<param name="class" value="xhsoft.douding.admin.controller.Hello" />
</create>
<strong><span style="color:#ff0000;"><convert converter="bean" match="xhsoft.douding.base.model.bean.ClassInfo" /></span></strong>
</allow>
</dwr>
3.在页面javascript处调用时,注意返回数据的解析
hello.getBean(function(bean){
console.log(bean["id"]);
});