[구조]


  • ItemVO.java
    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;
    	}
    }
    

  • IndexController.java
    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
    		//상품 리스트 가져오기
    		List itemList = 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;
    	}
    }
    

  • Shop.java
    import java.util.List;
    
    public interface Shop {
    	
    	List getItemList();
    }
    

  • ShopImpl.java
    import java.util.List;
    
    public class ShopImpl implements Shop {
    
    	private ItemCatalog itemCatalog;
    	
    	public void setItemCatalog(ItemCatalog itemCatalog) {
    		this.itemCatalog = itemCatalog;
    	}
    	
    	@Override
    	public List getItemList() {
    		// TODO Auto-generated method stub
    		return itemCatalog.getItemList();
    	}
    }
    

  • ItemCatalog.java
    import java.util.List;
    
    public interface ItemCatalog {
    
    	List getItemList();
    }
    

  • ItemCatalogImpl.java
    import java.util.List;
    
    public class ItemCatalogImpl implements ItemCatalog {
    	
    	private ItemDao itemDao;
    	
    	public void setItemDao(ItemDao itemDao) {
    		this.itemDao = itemDao;
    	}
    	
    	@Override
    	public List getItemList() {
    		// TODO Auto-generated method stub
    		return itemDao.findAll();
    	}
    }
    

  • ItemDao.java
    import java.util.List;
    
    public interface ItemDao {
    	List findAll();
    }
    

  • ItemDaoImpl.java
    import java.util.List;
    
    import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
    
    public class ItemDaoImpl extends SqlMapClientDaoSupport implements ItemDao {
    
    	@Override
    	public List findAll() {
    		// TODO Auto-generated method stub
    		return getSqlMapClientTemplate().queryForList("Shopping.all");
    	}
    }
    


  • web.xml
    
    
    	
    	
    		contextConfigLocation
    		/WEB-INF/applicationContext.xml
    	
    	
    	
    		
    			org.springframework.web.context.ContextLoaderListener
    		
    	
    
    
    	
    		shopping-1
    		org.springframework.web.servlet.DispatcherServlet
    		1
    	
    	
    	
    		shopping-1
    		*.html
    	
    	
    
    

  • applicationContext.xml
    
    
    
    	
    	
    		
    		
    		
    		
    	
    
    	
    	
    		
    		
    	
    
    

  • shopping-1-servlet.xml
    
    
    
    	
    	
    	
    	
    	
    		
    	
    	
    	
    	
    	
    	
    	
    		
    	
    	
    	
    		
    	
    	
    	
    		
    	
    	
    
    

  • SqlMapConfig.xml
    
    
    
    
    
    
    	
    
      	  
    
    


  • shopping.xml
    
    
    
    
    
    
    
    
    
    	
      	
    
  • SyntaxHighlighter가 브라우저에 따라 다르게 보이니... 정확한 소스는 압축파일을 다운 받아서 보시면 됩니다.



    [참고자료] : Spring 2.5 실무 프로그래밍 (성윤정)

    + Recent posts