jpetstore学习第2章 关于PetStoreFacade.java
如下是PetStoreFacade.java的代码,正如其自己所说 JPetStore primary business interface ,这确实是jpetstore的实现的核心之一。
PetSoreFacade.java
package org.springframework.samples.jpetstore.domain.logic;
import java.util.List;
import org.springframework.samples.jpetstore.domain.Account;
import org.springframework.samples.jpetstore.domain.Category;
import org.springframework.samples.jpetstore.domain.Item;
import org.springframework.samples.jpetstore.domain.Order;
import org.springframework.samples.jpetstore.domain.Product;
/**
* JPetStore primary business interface.
* @author Juergen Hoeller
* @since 30.11.2003
*/
public interface PetStoreFacade {
Account getAccount(String username);
Account getAccount(String username, String password);
void insertAccount(Account account);
void updateAccount(Account account);
List getUsernameList();
List getCategoryList();
Category getCategory(String categoryId);
List getProductListByCategory(String categoryId);
List searchProductList(String keywords);
Product getProduct(String productId);
List getItemListByProduct(String productId);
Item getItem(String itemId);
boolean isItemInStock(String itemId);
void insertOrder(Order order);
Order getOrder(int orderId);
List getOrdersByUsername(String username);
}
PetStore主要的系统对象有Account / Product / Item /Category/Order ,所以PetStoreFacade也基本上封装了对这几个对象的操作,根据Facade模式的用途,松散客户端和服务器端的耦合,提供了一个统一的界面来给客户端,去spring包下看所有的Controller类会发现,基本上所有的Controller类中都定义了PetStoreFacade的实例。而struts的实现干脆就是直接在所有Action的父类BaseAction中定义了PetStoreFacade的实例并在setServlet中将其初始化了
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
现在还没有搞清楚在什么时候调用setServlet这个函数。
浙公网安备 33010602011771号