DWR annotation

xiaoxiao2022-06-14  29

DWR annotation dwr2.0更新之后,给我们提供了annotation,它是针对jdk5里面提供的annotation来说的。而给我们提供annotation的好处是我们可以在dwr的开发中不用去配置繁琐 的dwr.xml文件,而把这个文件的配置信息都移植到程序中了。所以这也给我们提供了便利性,在我们开发中,我们就可以通过dwr的annotation来配置好这个配置信息 ,而不用去写一些繁琐的配置文件了。但是注意,如果要运用这个annotation,必须也需要去配置。而也个配置就相当于我们在web.xml中配置就可以了。完全我们就 可以抛弃dwr.xml文件了。 演示dwr提供的annotation,首先到文档中看一下dwr给我们提供的annotation 配置的第一步就是在web.xml中配置(这个就是需要注解的类): <  init-param  >                <  param-name  >  classes  </  param-name  >                <  param-value  >         com.spring.User,com.beans.Book              </  param-value  >  </  init-param  >

编写相关类            com.beans.Book:

@DataTransferObject(converter=BeanConverter.class)public   class  Book {    @RemoteProperty     private  String name;    @RemoteProperty     private  String author;

     public  String getAuthor() {         return  author;    }

     public   void  setAuthor(String author) {         this .author  =  author;    }

     public  String getName() {         return  name;    }

     public   void  setName(String name) {         this .name  =  name;    }}

@DataTransferObject: 标注在客户端和服务器之间转换类.对应dwr.xml中的<convert>标签.

 如果使用dwr.xml配置,可以这样:<convert converter="bean" match="com.beans.Book">  <param name="include" value="name, author"/></convert>@RemoteProxy(name="user",creator=SpringCreator.class,        creatorParams={            @Param(name="beanName",value="user")            })@DataTransferObject(converter=BeanConverter.class)public class User {    @RemoteProperty     private String welcome;    @RemoteProperty     private String username;    @RemoteProperty     private String address;    @RemoteProperty     private List<Book> books;    @RemoteProperty    private int age;

    public String getAddress() {        return address;    }

    public void setAddress(String address) {        this.address = address;    }

    public int getAge() {        return age;    }

    public void setAge(int age) {        this.age = age;    }    @RemoteMethod    public String getUsername() {        return username;    }

    public void setUsername(String username) {        this.username = username;    }

    public String getWelcome() {        return welcome;    }

    public void setWelcome(String welcome) {        this.welcome = welcome;    }    @RemoteMethod    public List<Book> getBooks() {        return books;    }        public void setBooks(List<Book> books) {        this.books = books;    }    @RemoteMethod    public User getUser(String welcome) {        this.welcome = welcome;        return this;    }

}

@RemoteProxy:标注要给远程调用的类.               RemoteProxy的name设置创造出来的对象的名字,creator指定使用那种创造器,例子中使用SpringCreator.creatorParams指定创造器的其他参数.不同的创造器参数是不同的.      @RemoteMethod:标注给远程调用的方法

 

相关资源:struts2.1 spring2.5 ibatis2.3 dwr3 annotation配置 集成
转载请注明原文地址: https://www.6miu.com/read-4936582.html

最新回复(0)