JSP

 

11번가 api

http://openapi.11st.co.kr/openapi/OpenApiGuide.tmall?commonGuideNo=2#none

 

 

xml 파싱을 위한 라이브러리 추가

 

https://mvnrepository.com/  에서  xml-apis 검색후 다운로드

https://mvnrepository.com/artifact/xml-apis/xml-apis/1.4.01

<!-- https://mvnrepository.com/artifact/xml-apis/xml-apis -->
<dependency>
    <groupId>xml-apis</groupId>
    <artifactId>xml-apis</artifactId>
    <version>1.4.01</version>
</dependency>

 

 

 

Api11stProductSearchParsing

 

package store;

import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.CharacterData;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;


//상품검색 - 기본정보조회

public class Api11stProductSearchParsing {

    private static Api11stProductSearchParsing instance = null;
    
    private final static String KEY ="키값";
    
    private final static String API_CODE="ProductSearch";
    
    private final static String URL_11ST="http://openapi.11st.co.kr/openapi/OpenApiService.tmall?key="+KEY+"&apiCode="+API_CODE;
        
    private Api11stProductSearchParsing(){ 
    	
    }
        
    public static Api11stProductSearchParsing getInstance() {
        if(instance == null) {
            instance = new Api11stProductSearchParsing();             
        }
        return instance;
    }
  
    private String getCharacterDataFromElement(Element e) {
        try {
            Node child = e.getFirstChild();
            if(child instanceof CharacterData) {
                CharacterData cd = (CharacterData) child;
                return cd.getData();
            }
        }catch(Exception ex) {
           ex.printStackTrace();
        }
        return "";          
    } 

    private String getElementValue(Element parent,String label) {
        return getCharacterDataFromElement((Element)parent.getElementsByTagName(label).item(0));  
    }

    
	/**
	key	String	O	OpenAPI 가입 시 발급받는 32자리 문자 Key
	 apiCode	String	O	OpenAPI 서비스 코드 → 상품검색 : ProductSearch
	 Keyword	String	O	검색 요청 값
	 pageNum	String	O	페이지 넘버(Default 1)
	pageSize	String	X	한페이지에 출력되는 상품 수(Default 50, 최대 200)
	sortCd	String	X	정렬순서
	    	→ CP : 인기도순
	    	→ A : 누적판매순
	    	→ G : 평가높은순
	    	→ I : 후기/리뷰많은순
	    	→ L : 낮은가격순
	    	→ H : 높은가격순
	    	→ N : 최근등록순
	option	String	X	Default로 제공되는 상품리스트 이외의 부가정보 요청 파라메터 입니다.
	 Categories : 카테고리 검색 결과 요청
	targetSearchPrd	String	X	상품 검색 대상(Default KOR) → ENG : 영문상품 → KOR : 국문상품
	*/ 
    //url 파라미터 셋팅
    protected static String urlParameterSetting(String keyword,String pageNum,String pageSize,String sortCd, String option, String categories, 
    		String targetSearchPrd, String categoryCode,boolean parameterValue) {
    	
    	String url=URL_11ST; 
    	String parameter="";
    		
		if(keyword!=null && !keyword.equals("")) {
    		try {				
    			parameter=parameter+"&keyword="+URLEncoder.encode(keyword , "UTF-8");
			} catch (UnsupportedEncodingException e) {				
				e.printStackTrace();
			}    		
    	}else{
    		parameter=parameter+"&keyword=";
    	}    	
    	
     	if(pageNum!=null && !pageNum.equals("")) parameter=parameter+"&pageNum="+pageNum;
    	
    	if(pageSize!=null && !pageSize.equals("")) parameter=parameter+"&pageSize="+pageSize;
    		
    	if(sortCd!=null && !sortCd.equals("")) parameter=parameter+"&sortCd="+sortCd;
    	
    	if(option!=null && !option.equals("")) parameter=parameter+"&option="+option;
    	
    	if(categories!=null && !categories.equals("")) parameter=parameter+"&Categories="+categories;
    	
    	if(targetSearchPrd!=null && !targetSearchPrd.equals("")) parameter=parameter+"&targetSearchPrd="+targetSearchPrd;
    	
    	if(categoryCode!=null && !categoryCode.equals("")) parameter=parameter+"&option=Categories&dispCtgrNo="+categoryCode;
    	
    	
    	
    	if(parameterValue){ //파라미터값 만 반환 할 경우 true 값
        	return parameter;
    	}
 
    	System.out.println("url+parameter : " +url+parameter);
    	return url+parameter;	
    }  
    
    
    
     
    public List<ProductSearch11stVO> xmlParsingProductList(String Keyword,String pageNum,String pageSize,String sortCd, String option, String Categories, String targetSearchPrd, String categoryCode) {
    	List<ProductSearch11stVO> productSearchList=null;
        try {
        	String url=urlParameterSetting(Keyword,pageNum,pageSize,sortCd,option,Categories,targetSearchPrd,categoryCode,false);

            DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            URL u = new URL(url);          
            Document doc = builder.parse(u.openStream());
          
            //전체 갯수
            NodeList nodesProductsRoot = doc.getElementsByTagName("Products");    
            Element rootElement = (Element)nodesProductsRoot.item(0);
            String totalCount=getElementValue(rootElement,"TotalCount");
            
            
            NodeList nodesProducts = doc.getElementsByTagName("Product");         
            productSearchList=new ArrayList<ProductSearch11stVO>();
            
            
            for(int i=0;i<nodesProducts.getLength();i++) {
              
                Element element = (Element)nodesProducts.item(i);
                ProductSearch11stVO productSearch =new ProductSearch11stVO();
                
                productSearch.setTotalCount(totalCount);                
                productSearch.setProductCode(getElementValue(element,"ProductCode"));			
                productSearch.setProductName(getElementValue(element,"ProductName"));			
                productSearch.setProductPrice(getElementValue(element,"ProductPrice"));  		
                productSearch.setProductImage(getElementValue(element,"ProductImage"));  		
                productSearch.setProductImage100(getElementValue(element,"ProductImage100"));
                productSearch.setProductImage110(getElementValue(element,"ProductImage110"));
                productSearch.setProductImage120(getElementValue(element,"ProductImage120"));
                productSearch.setProductImage130(getElementValue(element,"ProductImage130"));
                productSearch.setProductImage140(getElementValue(element,"ProductImage140"));
                productSearch.setProductImage150(getElementValue(element,"ProductImage150"));
                productSearch.setProductImage170(getElementValue(element,"ProductImage170"));
                productSearch.setProductImage200(getElementValue(element,"ProductImage200"));
                productSearch.setProductImage250(getElementValue(element,"ProductImage250"));
                productSearch.setProductImage270(getElementValue(element,"ProductImage270"));
                productSearch.setProductImage300(getElementValue(element,"ProductImage300"));
                productSearch.setText1(getElementValue(element,"Text1"));
                productSearch.setText2(getElementValue(element,"Text2"));
                productSearch.setSellerNick(getElementValue(element,"SellerNick")); 			 
                productSearch.setSeller(getElementValue(element,"Seller")); 				
                productSearch.setSellerGrd(getElementValue(element,"SellerGrd"));  			 
                productSearch.setRating(getElementValue(element,"Rating"));  			
                productSearch.setDetailPageUrl(getElementValue(element,"DetailPageUrl")); 		
                productSearch.setSalePrice(getElementValue(element,"SalePrice"));   		
                productSearch.setDelivery(getElementValue(element,"Delivery")); 			
                productSearch.setReviewCount(getElementValue(element,"ReviewCount")); 		
                productSearch.setBuySatisfy(getElementValue(element,"BuySatisfy")); 		
                productSearch.setMinorYn(getElementValue(element,"MinorYn")); 
                // Benefit 태그           
                NodeList benefit = element.getElementsByTagName("Benefit");
				for(int a = 0; a < benefit.getLength(); a++){
					Node nodeBenefit = benefit.item(a);
					if(nodeBenefit.getNodeType() == Node.ELEMENT_NODE){
						Element eleBenefit = (Element)nodeBenefit;
						productSearch.setDiscount(getElementValue(eleBenefit,"Discount")); 		
	                    productSearch.setMileage(getElementValue(eleBenefit,"Mileage"));
					}
				}

				productSearchList.add(productSearch);                
            }   
                        
        }catch(Exception ex) {
        	productSearchList=null;
            ex.printStackTrace();  
        }
      
        return productSearchList;
    }
    
    
   public List<Categories11stVO> xmlParsingCategories11st() {
    	List<Categories11stVO> categories11st=null;
       try {

          String url=URL_11ST; 
      	  String parameter="&keyword=&option=Categories";
      	  url=url+parameter;
      	  
           DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
           URL u = new URL(url);          
           Document doc = builder.parse(u.openStream());

           
           NodeList nodesCategorys = doc.getElementsByTagName("Category");         
           categories11st=new ArrayList<Categories11stVO>();
           
           
           for(int i=0;i<nodesCategorys.getLength();i++) {
             
               Element element = (Element)nodesCategorys.item(i);
               Categories11stVO categories11stVO =new Categories11stVO();

               categories11stVO.setCategoryPrdCnt(getElementValue(element,"CategoryPrdCnt")); 		
               categories11stVO.setCategoryName(getElementValue(element,"CategoryName"));
               categories11stVO.setCategoryUrl(getElementValue(element,"CategoryUrl"));
			   categories11st.add(categories11stVO);                
           }   
                       
       }catch(Exception ex) {
    	   categories11st=null;
           ex.printStackTrace();  
       }     
       return categories11st;
   }
    
    
    
    

}

 

 

ProductSearch11stVO

package store;

public class ProductSearch11stVO {
	
	private String totalCount;	
	private String productCode;			//상품 코드
	private String productName;			// 상품명
	private String productPrice;  		//상품 가격
	private String productImage;  		// 상품 대표 이미지
	private String productImage100;
	private String productImage110;
	private String productImage120;
	private String productImage130;
	private String productImage140;
	private String productImage150;
	private String productImage170;
	private String productImage200;
	private String productImage250;
	private String productImage270;
	private String productImage300;
	private String text1;
	private String text2;
	private String sellerNick; 			//핸드맥스 
	private String seller; 				// koreca
	private String sellerGrd;  			// 핸드맥스 
	private String rating;  			//  29
	private String detailPageUrl; 		// http://www.11st.co.kr/product/SellerProductDetail.tmall?method=getSellerProductDetail&prdNo=786813507
	private String salePrice;   		//3500
	private String delivery; 			//	무료  , /착불/선결제
	private String reviewCount; 		//262
	private String buySatisfy; 		//97
	private String minorYn; 			// Y , N
   
	// Benefit 태그           	
	private String discount;  			// 141000
	private String mileage;  			//
	
	
	public String getTotalCount() {
		return totalCount;
	}
	public void setTotalCount(String totalCount) {
		this.totalCount = totalCount;
	}
	public String getProductCode() {
		return productCode;
	}
	public void setProductCode(String productCode) {
		this.productCode = productCode;
	}
	public String getProductName() {
		return productName;
	}
	public void setProductName(String productName) {
		this.productName = productName;
	}
	public String getProductPrice() {
		return productPrice;
	}
	public void setProductPrice(String productPrice) {
		this.productPrice = productPrice;
	}
	public String getProductImage() {
		return productImage;
	}
	public void setProductImage(String productImage) {
		this.productImage = productImage;
	}
	public String getProductImage100() {
		return productImage100;
	}
	public void setProductImage100(String productImage100) {
		this.productImage100 = productImage100;
	}
	public String getProductImage110() {
		return productImage110;
	}
	public void setProductImage110(String productImage110) {
		this.productImage110 = productImage110;
	}
	public String getProductImage120() {
		return productImage120;
	}
	public void setProductImage120(String productImage120) {
		this.productImage120 = productImage120;
	}
	public String getProductImage130() {
		return productImage130;
	}
	public void setProductImage130(String productImage130) {
		this.productImage130 = productImage130;
	}
	public String getProductImage140() {
		return productImage140;
	}
	public void setProductImage140(String productImage140) {
		this.productImage140 = productImage140;
	}
	public String getProductImage150() {
		return productImage150;
	}
	public void setProductImage150(String productImage150) {
		this.productImage150 = productImage150;
	}
	public String getProductImage170() {
		return productImage170;
	}
	public void setProductImage170(String productImage170) {
		this.productImage170 = productImage170;
	}
	public String getProductImage200() {
		return productImage200;
	}
	public void setProductImage200(String productImage200) {
		this.productImage200 = productImage200;
	}
	public String getProductImage250() {
		return productImage250;
	}
	public void setProductImage250(String productImage250) {
		this.productImage250 = productImage250;
	}
	public String getProductImage270() {
		return productImage270;
	}
	public void setProductImage270(String productImage270) {
		this.productImage270 = productImage270;
	}
	public String getProductImage300() {
		return productImage300;
	}
	public void setProductImage300(String productImage300) {
		this.productImage300 = productImage300;
	}
	public String getText1() {
		return text1;
	}
	public void setText1(String text1) {
		this.text1 = text1;
	}
	public String getText2() {
		return text2;
	}
	public void setText2(String text2) {
		this.text2 = text2;
	}
	public String getSellerNick() {
		return sellerNick;
	}
	public void setSellerNick(String sellerNick) {
		this.sellerNick = sellerNick;
	}
	public String getSeller() {
		return seller;
	}
	public void setSeller(String seller) {
		this.seller = seller;
	}
	public String getSellerGrd() {
		return sellerGrd;
	}
	public void setSellerGrd(String sellerGrd) {
		this.sellerGrd = sellerGrd;
	}
	public String getRating() {
		return rating;
	}
	public void setRating(String rating) {
		this.rating = rating;
	}
	public String getDetailPageUrl() {
		return detailPageUrl;
	}
	public void setDetailPageUrl(String detailPageUrl) {
		this.detailPageUrl = detailPageUrl;
	}
	public String getSalePrice() {
		return salePrice;
	}
	public void setSalePrice(String salePrice) {
		this.salePrice = salePrice;
	}
	public String getDelivery() {
		return delivery;
	}
	public void setDelivery(String delivery) {
		this.delivery = delivery;
	}
	public String getReviewCount() {
		return reviewCount;
	}
	public void setReviewCount(String reviewCount) {
		this.reviewCount = reviewCount;
	}
	public String getBuySatisfy() {
		return buySatisfy;
	}
	public void setBuySatisfy(String buySatisfy) {
		this.buySatisfy = buySatisfy;
	}
	public String getMinorYn() {
		return minorYn;
	}
	public void setMinorYn(String minorYn) {
		this.minorYn = minorYn;
	}
	public String getDiscount() {
		return discount;
	}
	public void setDiscount(String discount) {
		this.discount = discount;
	}
	public String getMileage() {
		return mileage;
	}
	public void setMileage(String mileage) {
		this.mileage = mileage;
	}
	
	
	@Override
	public String toString() {
		return "ProductSearch [totalCount=" + totalCount + ", productCode=" + productCode + ", productName="
				+ productName + ", productPrice=" + productPrice + ", productImage=" + productImage
				+ ", productImage100=" + productImage100 + ", productImage110=" + productImage110 + ", productImage120="
				+ productImage120 + ", productImage130=" + productImage130 + ", productImage140=" + productImage140
				+ ", productImage150=" + productImage150 + ", productImage170=" + productImage170 + ", productImage200="
				+ productImage200 + ", productImage250=" + productImage250 + ", productImage270=" + productImage270
				+ ", productImage300=" + productImage300 + ", text1=" + text1 + ", text2=" + text2 + ", sellerNick="
				+ sellerNick + ", seller=" + seller + ", sellerGrd=" + sellerGrd + ", rating=" + rating
				+ ", detailPageUrl=" + detailPageUrl + ", salePrice=" + salePrice + ", delivery=" + delivery
				+ ", reviewCount=" + reviewCount + ", buySatisfy=" + buySatisfy + ", minorYn=" + minorYn + ", discount="
				+ discount + ", mileage=" + mileage + "]";
	}
			
	
}




 

 

 

 

 

Categories11stVO

카테고리만 파싱

package store;

public class Categories11stVO {

	private String categoryPrdCnt;
	private String categoryName;
	private String categoryUrl;
	
	
	public String getCategoryPrdCnt() {
		return categoryPrdCnt;
	}
	public void setCategoryPrdCnt(String categoryPrdCnt) {
		this.categoryPrdCnt = categoryPrdCnt;
	}
	public String getCategoryName() {
		return categoryName;
	}
	public void setCategoryName(String categoryName) {
		this.categoryName = categoryName;
	}
	public String getCategoryUrl() {
		return categoryUrl;
	}
	public void setCategoryUrl(String categoryUrl) {
		this.categoryUrl = categoryUrl;
	}
	
	@Override
	public String toString() {
		return "Categories11st [categoryPrdCnt=" + categoryPrdCnt + ", categoryName=" + categoryName + ", categoryUrl="
				+ categoryUrl + "]";
	}
	
	
	
}

 

 

 

PageMakerAndSearch

페이징 처리

package store;


//MySQL PageMaker
public class PageMakerAndSearch {
	// mysql 들어갈 값은 page 가 아니라 pageStart, perPageNum 이다.
	// limit #{pageStart}, #{perPageNum}
	private int page;
	private int perPageNum;
	private int pageStart;

	// 하단 페이징 << 1 2 3 4 5 6 7 8 9 10 >>
	private int totalCount; // 전체 개수
	private int startPage; // 시작 페이지
	private int endPage; // 끝페이지
	private boolean prev; // 이전 여부
	private boolean next; // 다음 여부

	private int displayPageNum = 10;

	private int tempEndPage; // 마지막 페이지

	// 검색처리 추가
	private String searchType;
	
	private String keyword;	
	private String sortCd;	
	private String option;	
	private String categories;
	private String targetSearchPrd;
	
	private String categoryCode;

	public PageMakerAndSearch() {
		this.page = 1; // 초기 페이지는 1
		this.perPageNum = 50; // limit 50 개씩 보여준다.
	}

	public void setPage(int page) {
		// 페이지 번호가 0이거나 0보다 작으면 1페이지로 한다.
		//
		if (page <= 0) {
			this.page = 1;
			return;
		}
		this.page = page;
	}

	// MyBatis SQL 의 Mapper 에서 인식해서 가져가는 파라미터 값 메소드 #{perPageNum}
	public void setPerPageNum(int perPageNum) {
		// 몇개 씩 보여줄것인가 이다. 최대 100개씩 보여 줄것으로 설정한다.
		// 만약 0보다 작거나 100 보다 크면 10으로 초기화 시킨다.
		if (perPageNum <= 0 || perPageNum > 200) {
			this.perPageNum = 50;
			return;
		}
		this.perPageNum = perPageNum;
	}

	// MyBatis SQL 의 Mapper 에서 인식해서 가져가는 파라미터 값 메소드 #{pageStart}
	public int getPageStart() {
		// 실질적으로 Mybatis 에서 파라미터로 인식해서 가져오는 것은 get 이다.
		// 따라서 getPageStart 에서 값을 설정한다.
		// 시작 데이터 번호 = (페이지 번호 -1 ) * 페이지당 보여지는 개수
		this.pageStart = (this.page - 1) * perPageNum;
		return this.pageStart;
	}

	// 전체 페이지 설정과 동시에 하단에 뿌려질 페이지 계산하기
	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
		calcData();
	}

	private void calcData() {
		// 현재 페이지 번호 / 하단 페이지번호 수
		endPage = (int) (Math.ceil(page / (double) displayPageNum) * displayPageNum);

		startPage = (endPage - displayPageNum) + 1;

		tempEndPage = (int) (Math.ceil(totalCount / (double) perPageNum));

		if (endPage > tempEndPage) {
			endPage = tempEndPage;
		}

		prev = startPage == 1 ? false : true;
		next = endPage * perPageNum >= totalCount ? false : true;
	}


	// 검색 추가 페이지 파라미터
	public String makeSearch(int page) {
		//pageSize	String	X	한페이지에 출력되는 상품 수(Default 50, 최대 200)		
		String pageNum=	String.valueOf(page);
		String pageSize=String.valueOf(this.perPageNum);
		return Api11stProductSearchParsing.urlParameterSetting(this.keyword, pageNum, pageSize, this.sortCd, this.option, this.categories, this.targetSearchPrd, this.categoryCode, true);		
	}

	// 검색 추가 페이징 부트스트랩 출력
	public String bootStrapPagingSearchHTML(String url) {
		StringBuffer sBuffer = new StringBuffer();
		sBuffer.append("<ul class='pagination'>");
		if (prev) {
			sBuffer.append("<li><a href='" + url + makeSearch(1) + "'><<</a></li>");
		}

		if (prev) {
			sBuffer.append("<li><a href='" + url + makeSearch(startPage - 1) + "'><</a></li>");
		}

		String active = "";
		for (int i = startPage; i <= endPage; i++) {
			if (page == i) {
				active = "class=active";
			} else {
				active = "";
			}
			sBuffer.append("<li " + active + " >");
			sBuffer.append("<a href='" + url + makeSearch(i) + "'>" + i + "</a></li>");
			sBuffer.append("</li>");
		}

		if (next && endPage > 0) {
			sBuffer.append("<li><a href='" + url + makeSearch(endPage + 1) + "'>></a></li>");
		}

		if (next && endPage > 0) {
			//sBuffer.append("<li><a href='" + url + makeSearch(tempEndPage) + "'>마지막</a></li>");
		}

		sBuffer.append("</ul>");
		return sBuffer.toString();
	}

	public int getPage() {
		return page;
	}

	public int getPerPageNum() {
		return perPageNum;
	}

	public void setPageStart(int pageStart) {
		this.pageStart = pageStart;
	}

	public int getTotalCount() {
		return totalCount;
	}

	public int getStartPage() {
		return startPage;
	}

	public void setStartPage(int startPage) {
		this.startPage = startPage;
	}

	public int getEndPage() {
		return endPage;
	}

	public void setEndPage(int endPage) {
		this.endPage = endPage;
	}

	public boolean isPrev() {
		return prev;
	}

	public void setPrev(boolean prev) {
		this.prev = prev;
	}

	public boolean isNext() {
		return next;
	}

	public void setNext(boolean next) {
		this.next = next;
	}

	public int getDisplayPageNum() {
		return displayPageNum;
	}

	public void setDisplayPageNum(int displayPageNum) {
		this.displayPageNum = displayPageNum;
	}

	public String getSearchType() {
		return searchType;
	}

	public void setSearchType(String searchType) {
		this.searchType = searchType;
	}

	public String getKeyword() {
		return keyword;
	}

	public void setKeyword(String keyword) {
		this.keyword = keyword;
	}

	public int getTempEndPage() {
		return tempEndPage;
	}

	public void setTempEndPage(int tempEndPage) {
		this.tempEndPage = tempEndPage;
	}

	public String getSortCd() {
		return sortCd;
	}

	public void setSortCd(String sortCd) {
		this.sortCd = sortCd;
	}

	public String getOption() {
		return option;
	}

	public void setOption(String option) {
		this.option = option;
	}

	public String getCategories() {
		return categories;
	}

	public void setCategories(String categories) {
		this.categories = categories;
	}

	public String getTargetSearchPrd() {
		return targetSearchPrd;
	}

	public void setTargetSearchPrd(String targetSearchPrd) {
		this.targetSearchPrd = targetSearchPrd;
	}

	
	public String getCategoryCode() {
		return categoryCode;
	}

	public void setCategoryCode(String categoryCode) {
		this.categoryCode = categoryCode;
	}

	@Override
	public String toString() {
		return "PageMakerAndSearch [page=" + page + ", perPageNum=" + perPageNum + ", pageStart=" + pageStart
				+ ", totalCount=" + totalCount + ", startPage=" + startPage + ", endPage=" + endPage + ", prev=" + prev
				+ ", next=" + next + ", displayPageNum=" + displayPageNum + ", tempEndPage=" + tempEndPage
				+ ", searchType=" + searchType + ", keyword=" + keyword + ", sortCd=" + sortCd + ", option=" + option
				+ ", categories=" + categories + ", targetSearchPrd=" + targetSearchPrd + ", categoryCode="
				+ categoryCode + "]";
	}



}

 

 

 

store.jsp

<%@page import="store.Categories11stVO"%>
<%@page import="store.PageMakerAndSearch"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@page import="store.ProductSearch11stVO"%>
<%@page import="java.util.List"%>
<%@page import="store.Api11stProductSearchParsing"%>
<%@ page import="java.text.*" %>
<%
	NumberFormat nf = NumberFormat.getNumberInstance();
%>
<%
	String keyword = request.getParameter("keyword");
	String pageNum = request.getParameter("pageNum");
	String pageSize = request.getParameter("pageSize");
	String sortCd = request.getParameter("sortCd");
	String option = request.getParameter("option");
	String categories =request.getParameter("categories");
	String targetSearchPrd = request.getParameter("targetSearchPrd");
	String categoryCode=request.getParameter("categoryCode");

	int totalCount=0;
	String paging=null;
	//현재 페이지 url
	StringBuffer currentURL=request.getRequestURL();
	
	Api11stProductSearchParsing api11st = Api11stProductSearchParsing.getInstance();	
	List<ProductSearch11stVO> productList = api11st.xmlParsingProductList(keyword, pageNum, pageSize, sortCd, option, categories,targetSearchPrd, categoryCode);

	if(productList!=null && productList.size() >0){
		PageMakerAndSearch pageMaker=new PageMakerAndSearch();
		
		if(pageNum!=null && !pageNum.equals("")){
			pageMaker.setPage(Integer.parseInt(pageNum));
		}
		
		if(pageSize!=null && !pageSize.equals("")){
			pageMaker.setPerPageNum(Integer.parseInt(pageSize));
		}
		totalCount=Integer.parseInt(productList.get(0).getTotalCount()); 		
		pageMaker.setKeyword(keyword);
		
		if(pageSize==null || pageSize.equals("")) {
			pageMaker.setPerPageNum(50);
		}else{
			pageMaker.setPerPageNum(Integer.parseInt(pageSize));
		}

		pageMaker.setSortCd(sortCd);
		pageMaker.setOption(option);
		pageMaker.setCategories(categories);
		pageMaker.setTargetSearchPrd(targetSearchPrd);		
		pageMaker.setTotalCount(totalCount);
		
		paging=pageMaker.bootStrapPagingSearchHTML(currentURL.toString()+"?");
	}
	
	List<Categories11stVO> categories11st=api11st.xmlParsingCategories11st();
	//System.out.println("카테고리 목록 :" + categories11st.size());
	
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width" initial-scale="1">
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="css/custom.css">
<title>SPROUT</title>
</head>
<body>

	<%@ include file="common/menu.jsp"%>

	<div class="container">
		<div class="row">

			<form class="form-inline" id="searchFrm">
				<div class="form-group">
					<select name="categoryCode" class="form-control">
					   <option value=""  <%if(categoryCode==null||categoryCode.equals("")) out.print("selected");%> >카테고리 검색</option>
						<%
							for(Categories11stVO vo  : categories11st ){
						%>
							<option value="<%= vo.getCategoryPrdCnt() %>" <%if(categoryCode!=null&& categoryCode.equals(vo.getCategoryPrdCnt() )) out.print("selected");%> ><%= vo.getCategoryName() %></option>			
					 	<%								
							}
						
						%>
					</select>
					
				</div>
				<div class="form-group">
					<select name="pageSize" class="form-control">
						<option value="5"  <%if(pageSize!=null&&pageSize.equals("5")) out.print("selected");%> >5</option>
						<option value="10"  <%if(pageSize!=null&&pageSize.equals("10")) out.print("selected");%> >10</option>
						<option value="30"  <%if(pageSize!=null&&pageSize.equals("30")) out.print("selected");%> >30</option>
						<option value="50"  <%if(pageSize ==null ||pageSize.equals("50")) out.print("selected");%> >50</option>
						<option value="100"  <%if(pageSize!=null&&pageSize.equals("100")) out.print("selected");%> >100</option>
						<option value="150"  <%if(pageSize!=null&&pageSize.equals("150")) out.print("selected");%>>150</option>
						<option value="200"  <%if(pageSize!=null&&pageSize.equals("200")) out.print("selected");%> >200</option>
					</select>
				</div>				
				
<!-- 			sortCd	String	X	정렬순서
			    	→ CP : 인기도순
			    	→ A : 누적판매순
			    	→ G : 평가높은순
			    	→ I : 후기/리뷰많은순
			    	→ L : 낮은가격순
			    	→ H : 높은가격순
			    	→ N : 최근등록순 
	    	-->
				<div class="form-group">
					<select name="sortCd" class="form-control">
						<option value="X" <%if(sortCd!=null&&sortCd.equals("X")) out.print("selected");%> >정렬순서</option>
						<option value="CP" <%if(sortCd!=null&&sortCd.equals("CP")) out.print("selected");%> >인기도순</option>
						<option value="A" <%if(sortCd!=null&&sortCd.equals("A")) out.print("selected");%> >누적판매순</option>
						<option value="G" <%if(sortCd!=null&&sortCd.equals("G")) out.print("selected");%> >평가높은순</option>
						<option value="I" <%if(sortCd!=null&&sortCd.equals("I")) out.print("selected");%> >후기/리뷰많은순</option>
						<option value="L" <%if(sortCd!=null&&sortCd.equals("L")) out.print("selected");%> >낮은가격순</option>
						<option value="H <%if(sortCd!=null&&sortCd.equals("H")) out.print("selected");%> ">높은가격순</option>
						<option value="N" <%if(sortCd!=null&&sortCd.equals("N")) out.print("selected");%>  >최근등록순</option>
					</select>
				</div>
		
				<div class="form-group">
					<select name="targetSearchPrd" class="form-control">
						<option value="" <%if(targetSearchPrd==null||targetSearchPrd.equals("")) out.print("selected");%> >상품 검색 대상</option>
						<option value="KOR" <%if(targetSearchPrd!=null&&targetSearchPrd.equals("KOR")) out.print("selected");%> >국문상품</option>
						<option value="ENG" <%if(targetSearchPrd!=null&&targetSearchPrd.equals("ENG")) out.print("selected");%> >영문상품</option>
					</select>
				</div>
				
				<div class="form-group">
					<input type="text" class="form-control" placeholder="검색어를 입력하세요" name="keyword" maxlength="20" id="keyword" value="<%if(keyword!=null&& !keyword.equals("")) out.print(keyword);%>">
				</div>
				<div class="form-group">
					<button  class="btn btn-primary">검색</button>
					<button type="button" class="btn btn-primary" onclick="searchReset()">검색 초기화</button>
				</div>
				
			   <div class="text-right totalCount">
			   		<%=nf.format(totalCount)%> 건				
				</div>
			</form>

			<table class="table table-hover table-responsive" id="products_11_st">
				<thead class="text-center">
					<tr>
						<th class="text-center">상품</th>
						<th class="text-center" width="10%">가격</th>
					</tr>
				</thead>

				<tbody>
					<%
						if (productList != null && productList.size() > 0) {
									for (ProductSearch11stVO product : productList) {
					%>
					<tr class="text-center">
						
						<td class="text-left">

							<div class="row">
								<div class="col-12 col-sm-3">
									<a href="<%=product.getDetailPageUrl()%>" target="_blank">
										<img src="<%=product.getProductImage170()%>">
									</a>
								</div>

								<div class="col-12 col-sm-9">
									<div class="row">
										<div class="c_prd_name col-sm-12">
											<a href="<%=product.getDetailPageUrl()%>" target="_blank"><strong><%=product.getProductName()%></strong></a>
										</div>


										<div class="col-sm-12 c_prd_meta">

										<div class="wrap-star">										   
										    <div class='star-rating'>
										        <span style ="width:<%=product.getRating()%>%"></span>		
										    </div>
										    	<%
										    		if(product.getReviewCount()!=null && !product.getReviewCount().equals("") ){										    			
										    			if(Integer.parseInt(product.getReviewCount()) >0){
										    	%>
										    	<a href="#" class="c_review" onclick="return false">
													<span class="title">리뷰</span>
													<em><%=product.getReviewCount()%></em><span class="unit">건</span>
											    </a>										    	
										    	<%			
										    			}
										    		}
										    	%>										    
										</div> 							        
												
										</div>


										<div class="col-sm-12">
											<div class="text-delivery">
											<%
											
												if(product.getDelivery()!=null & !product.getDelivery().equals("")){													
													if(product.getDelivery().equals("무료")){
														out.print(product.getDelivery());
													}else{
														out.print("배송비 2,500원");
													}
												}
											%>
											</div>
										</div>
										
										<div class="col-sm-12">
											<div class="c_prd_sellerNick">										
											<span class="name"><%=product.getSellerNick()%></span>
											</div>
										</div>
									</div>

								</div>
							</div>



						</td>
						<td><strong class="price_seller"><%=nf.format(Integer.parseInt(product.getSalePrice()))%></strong>
							<span class="text-unit">원</span>
						</td>
					</tr>
					<%
						}
					} else {
					%>
					<tr class="text-center">
						<td colspan="3" class="text-center"><h3>검색결과가 없습니다.</h3></td>
					</tr>
					<%
						}
					%>
				</tbody>
				<tfoot>
					<tr>
					<td colspan="3" class="text-center">
						<%  if(paging!=null)out.print(paging);%>
					</td>
					</tr>
				</tfoot>
			</table>



		</div>
	</div>






	<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
	<script src="js/bootstrap.js"></script>
	
<script type="text/javascript">
function searchReset(){
	location.href="<%=currentURL.toString()+"?&keyword="%>";
}

</script>	
</body>
</html>

 

 

 

 

 

jsp

 

about author

PHRASE

Level 60  라이트

인생은 한 권의 책과 같다. 어리석은 사람은 대충 책장을 넘기지만, 현명한 사람은 공들여서 읽는다. 그들은 단 한 번 밖에 읽지 못하는 것을 알기 때문이다. -장 파울-

댓글 ( 4)

댓글 남기기

작성