[구조]
public class ItemVO { private int itemId; private String itemName; private int price; private String description; private String pictureUrl; public int getItemId() { return itemId; } public void setItemId(int itemId) { this.itemId = itemId; } public String getItemName() { return itemName; } public void setItemName(String itemName) { this.itemName = itemName; } public int getPrice() { return price; } public void setPrice(int price) { this.price = price; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public String getPictureUrl() { return pictureUrl; } public void setPictureUrl(String pictureUrl) { this.pictureUrl = pictureUrl; } }
import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.Controller; public class IndexController implements Controller { private Shop shop; public void setShop(Shop shop) { this.shop = shop; } @Override public ModelAndView handleRequest(HttpServletRequest rq, HttpServletResponse rs) throws Exception { // TODO Auto-generated method stub //상품 리스트 가져오기 ListitemList = this.shop.getItemList(); //모델 작성 Map model = new HashMap(); model.put("itemList", itemList); System.out.println("==================================================="); System.out.println("itemList size : " + itemList.size()); //뷰 작성 ModelAndView modelAndView = new ModelAndView(); modelAndView.setViewName("/WEB-INF/jsp/index.jsp"); modelAndView.addAllObjects(model); return modelAndView; } }
import java.util.List; public interface Shop { ListgetItemList(); }
import java.util.List; public class ShopImpl implements Shop { private ItemCatalog itemCatalog; public void setItemCatalog(ItemCatalog itemCatalog) { this.itemCatalog = itemCatalog; } @Override public ListgetItemList() { // TODO Auto-generated method stub return itemCatalog.getItemList(); } }
import java.util.List; public interface ItemCatalog { ListgetItemList(); }
import java.util.List; public class ItemCatalogImpl implements ItemCatalog { private ItemDao itemDao; public void setItemDao(ItemDao itemDao) { this.itemDao = itemDao; } @Override public ListgetItemList() { // TODO Auto-generated method stub return itemDao.findAll(); } }
import java.util.List; public interface ItemDao { ListfindAll(); }
import java.util.List; import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport; public class ItemDaoImpl extends SqlMapClientDaoSupport implements ItemDao { @Override public ListfindAll() { // TODO Auto-generated method stub return getSqlMapClientTemplate().queryForList("Shopping.all"); } }
contextConfigLocation /WEB-INF/applicationContext.xml org.springframework.web.context.ContextLoaderListener shopping-1 org.springframework.web.servlet.DispatcherServlet 1 shopping-1 *.html
[참고자료] : Spring 2.5 실무 프로그래밍 (성윤정) |
'프로그램 > Spring 2.5' 카테고리의 다른 글
[17일차] spring MVC 예제 - 1 (AbstractController, Controller) (2) | 2012.02.10 |
---|---|
[참고] Developing a Spring Framework MVC application step-by-step (0) | 2012.02.08 |
[15일차] DispatcherServlet 설정 (0) | 2010.11.02 |
[14일차] Spring MVC의 클라이언트 요청 처리 과정 (6) | 2010.11.02 |
[13일차] SpringFramework + ibatis 연동 (2) (0) | 2010.06.27 |