DWR应用程序的起点是编写服务器端对象模型。在这个示例中,我从编写 DAO 开始,用它提供对产品目录数据存储的搜索功能。CatalogDAO.java 是一个简单的无状态的类,有一个无参数的构造函数。清单 1 显示了我想要公开给 Ajax 客户的 Java 方法的签名:
清单 1. 通过 DWR 公开的 CatalogDAO 方法
/**
* Returns a list of items in the catalog that have
* names or descriptions matching the search expression
* @param expression Text to search for in item names
* and descriptions
* @return list of all matching items
*/
public List<Item> findItems(String expression);
/**
* Returns the Item corresponding to a given Item ID
* @param id The ID code of the item
* @return the matching Item
*/
public Item getItem(String id);