체크된 값만 받기
goOrder();

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<c:import url="/top"/>

<h1 class="text-success text-center">${loginUser.name} [${loginUser.userid}]님 장바구니</h1>
<!-- 주문 폼 시작--------------------- -->
<form name="orderF" id="orderF" action="orderSheet">
	<table class="table table-striped">
		<thead>
		<tr class="info">
			<th class="text-center">상품번호</th>
			<th class="text-center">상품명</th>
			<th class="text-center">수량</th>
			<th class="text-center">단가</th>
			<th class="text-center">금액</th>
			<th class="text-center">삭제</th>
		</tr>
		</thead>
		<tbody>
		<c:if test="${cartList eq null or empty cartList}">
			<tr>
				<td colspan="6"><b>담긴 상품이 없습니다.</b></td>
			</tr>
		</c:if>
		<c:if test="${cartList ne null and not empty cartList}">
		<!-- ---------반복문-------------- -->
		<c:forEach var="cp" items="${cartList}" varStatus="st">
		<tr>
			<td>
			<label>
				<input type="checkbox" name="opnum" id="pnum${st.count}" value="${cp.pnum}">${cp.pnum}
			</label>
			</td>
			<td>
				${cp.pname}<br>
				<a href="../prodDetail.do?pnum=${cp.pnum}" target="_blank">
				<img src="../images/${cp.pimage1}" class="img-thumbnail"
				alt="${cp.pname }"
				style="width:140px"></a>
			</td>
			<td>
			<input type="number" name="oqty" id="oqty${st.count}" value="${cp.oqty}" min="1" max="50" size="3"> 개
			<button type="button" class="btn btn-info" onclick="cartEdit('${cp.cartNum}','${st.count}')">수정</button>
			</td>
			<td>
				<fmt:formatNumber value="${cp.saleprice}" pattern="###,###"/>원
				<br>
				<span class="badge badge-danger">${cp.point}</span>POINT
			</td>
			<td style="font-weight:bold">
				<fmt:formatNumber value="${cp.totalPrice}" pattern="###,###"/>원
				<br>
				<span class="badge badge-danger">${cp.totalPoint}</span>POINT
			</td>
			<td>
			<a class="btn btn-outline-danger" onclick="cartDel('${cp.cartNum}','${cp.pnum}')">삭제</a>
			</td>
		</tr>
		</c:forEach>
		</c:if>
		<!-- ---------------------------- -->
		
		<tr>
			<td colspan="3">
				<h5>장바구니 총      액: 
				<span class="text-danger">
				<fmt:formatNumber value="${cartTotalPrice}" pattern="###,###"/>
				</span> 원</h5>
				<h5>장바구니 총포인트: 
				<span class="text-success">
				<fmt:formatNumber value="${cartTotalPoint}" pattern="###,###"/>
				</span> point</h5>
			</td>
			<td colspan="3">
				<button type="button" onclick="goOrder()" class="btn btn-warning">주문하기</button>
				<button type="button" class="btn btn-success" 
				onclick="location.href='../index.do'">계속쇼핑</button>
			</td>
		</tr>
		
		</tbody>
	</table>
</form>
<!-- 주문폼 end--------------------- -->

<!-- 삭제 폼 시작-------------------- -->
<form name="df" action="cartDel">
	<input type="hidden" name="cartNum">
</form>

<!-- 수정 폼 시작-------------------- -->
<form name="ef" action="cartEdit">
	<input type="hidden" name="cartNum">
	<input type="hidden" name="oqty">
</form>
<!-- ---------------------------- -->
<script>
	/*체크박스에 체크한 상품(상품번호,주문수량)을 가지고 주문 폼 페이지로 이동*/
	function goOrder(){
		//1. 장바구니에 담긴 상품이 없는 경우
		var chk=$('input[name="opnum"]');
		if(chk.length==0){
			return;
		}
		//2. 담긴 상품이 있다면 체크박스 갯수 만큼 반복문 돌면서 체크한 상품과 체크 안된 상품을 구분하여, 체크 안된 상품의 주문 수량은 서버쪽에 적송되지 않도록 disabled 처리한다.
		var cnt =0;
		$.each(chk,function(i,ch){
			if($(ch).is(":checked")){
				cnt++;
				$('#oqty'+(i+1)).prop('disabled',false);//비활성화
			}else{
				//체크 안된 상품의 주문 수량 비활성화 
				$('#oqty'+(i+1)).prop('disabled',true);//비활성화
			}
		});

		if(cnt==0){
			alert('주문할 상품을 체크하세요');
			$('input[name="oqty"]').prop('disabled',false);//비활성화
			return;	
		}
		orderF.submit();
	}

	
	function cartEdit(num,count){
		//alert(num+"/"+count);
		ef.cartNum.value=num;
		var qty=$('#oqty'+count).val(); //수정된 수량값을 알 수 있음
		//alert(qty);
		ef.oqty.value=qty;
		ef.method='post';
		ef.submit();
	}//----------------------------

	function cartDel(num, pnum){
		//alert(num);
		var yn=confirm(pnum+'번 상품을 정말 삭제하시겠습니까?');
		if(yn){
		df.cartNum.value=num;
		df.method='post';
		df.submit();
		}
	}
</script>

<c:import url="/foot"/>

주문처리
OrderController.java

package com.tis.myshop;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.tis.domain.OrderVO;
import com.tis.domain.ProductVO;
import com.tis.domain.ReceiverVO;
import com.tis.domain.UserVO;
import com.tis.service.OrderService;
import com.tis.service.ShopService;

import lombok.extern.log4j.Log4j;

@Controller
@RequestMapping("/user")
@Log4j
public class OrderController {
	
	@Inject 
	private ShopService shopSvc;
	
	@Inject
	private OrderService orderSvc;
	
	@RequestMapping("/orderSheet")
	public String orderForm(Model model, HttpSession ses, 
			@RequestParam("opnum") int[] opnum,
			@RequestParam("oqty") int[] oqty) {
		
		log.info("opnum=="+opnum[0]+", oqty=="+oqty[0]);
		//주문한 상품정보를 DB에서 가져오기 
		List<ProductVO> orderList = new ArrayList<>();
		if(opnum!=null &&oqty!=null) {
			for (int i = 0; i < opnum.length; i++) {
				int pnum = opnum[i];
				ProductVO prod = this.shopSvc.selectByPnum(pnum);
				//ProductVO에는 pqty(수량)==> 쇼핑몰 보유 수량
				//수량을 주문수량으로 변경하자.
				prod.setPqty(oqty[i]);
				orderList.add(prod);//주문목록에 상품 추가
			}
		}
		
		model.addAttribute("orderList",orderList);
		//세연에도 저장
		ses.setAttribute("orderList", orderList);
		
		//주문자의 마일리지 점수 가져오기
		UserVO loginUser = (UserVO)ses.getAttribute("loginUser");
		ses.setAttribute("mileage", loginUser.getMileage());
		
		
		return "shop/orderSheet";
	}
	
	//주문 처리하는 메소
	@RequestMapping("/orderAdd")
	public String orderAdd(Model model, HttpSession ses,
			@ModelAttribute("ovo") OrderVO ovo,
			@ModelAttribute("receiver") ReceiverVO receiver) {
		
		log.info("ovo=="+ovo);//주문총액, 총포인트, 배송비..등등
		log.info("receiver=="+receiver);//수령자 정보
		
		
		return "redirect:orderDetail?onum=";
	}
}

orderSheep.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c"
 uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" 
uri="http://java.sun.com/jsp/jstl/fmt" %>
<c:import url="/top"/>
<div class="row">

<div class="col-md-10 offset-md-1">
<h1 class="text-primary text-center mt-4">${loginUser.name}[ ${loginUser.userid} ]님의 주문정보</h1>

<table class="table table-responsive">
	<tr>
		<th colspan="5">주문 상품 정보</th>
	</tr>
	<tr bgcolor="#efefef" align="center">
		<td width="10%">상품번호</td>
		<td width="25%">상품명</td>
		<td width="30%">판매가</td>
		<td width="10%">수 량</td>
		<td width="25%">합계금액</td>
	</tr>
		<!-- --------------------- -->
		<c:set var="totalBuy" value="0"/> <!-- 총 주문가격 -->
		<c:set var="totalBuyPoint" value="0"/> <!-- 총 주문 누적포인트 -->
		<c:forEach var="p" items="${orderList}">
			<c:set var="totalBuy" value="${totalBuy+p.totalPrice}"/>
			<c:set var="totalBuyPoint" value="${totalBuyPoint+p.totalPoint}"/>
		<tr>
			<td>${p.pnum}</td>
			<td align="center">
			${p.pname}<br>
			<a href="../prodDetail?pnum=${p.pnum}" target="_blank"><img
				src="../images/${p.pimage1}"
				width="100" height="100" border="0" />
			</a>
			</td>
			<td align="right" style="padding-right:20px">
				<fmt:formatNumber value="${p.price }" pattern="###,###"/><br>
				[${p.point}] POINT
			</td>
			<td align="center">${p.pqty}개</td>
			<td  align="right" style="padding-right:20px">
			<b>
			<fmt:formatNumber value="${p.totalPrice}" pattern="###,###" />
			원<br />
			</b>
			<b>
			[${p.totalPoint}]POINT
			</b>
			</td>
		</tr>
		</c:forEach>
		<!-- ----------------------- -->

	<tr bgcolor="#efefef">
		<td colspan="2">주문일자<br />
		<b>
		<fmt:formatDate value="<%=new java.util.Date()%>" pattern="yyyy-MM-dd hh:mm:ss"/>
		</b>
		<br>
		<span style="font-size:1.5em;color:blue">배송비: 3,000원</span>
		</td>
		<td colspan="3" align="right">주문총금액: 
		<h2 class="text-primary" id="total">
		<fmt:formatNumber value="${totalBuy}" pattern="###,###" />원
		</h2><br/>
		[<font color=blue><b> ${totalBuyPoint}</b></font>]POINT<br/>
		<h1 class="text-danger">
		결제금액:
		<fmt:formatNumber value="${totalBuy+3000}" pattern="###,###"/>원
		</h1>
		</td>
	</tr>
	<!-- --------------------- -->
</table>
<br />
<!-- form 시작=================== -->
<form name="custF" action="orderAdd" method="POST">
<!-- ----------------------------------------------------- -->
<input	type="text" name="ototalPrice" id="ototalPrice" value="${totalBuy}" />
<input	type="text" name="ototalPoint" id="ototalPoint" value="${totalBuyPoint}" />
<input type="text" name="odeliverPrice" value="3000">
<input type="text" name="idx_fk" value="${loginUser.idx}">
<!-- hidden으로 주문총액과 총포인트를 넘기자-------------------- -->
<!--  -->
<!-- 마일리지 사용 부가결제금액 -->
		<div id="pointInfo" style="margin-top:20px;">
			    <table class="table table-bordered" >			
                <!-- 적립금 -->
                <tbody>
                <tr>
				<th scope="row" width="150px">사용가능 적립금</th>
                <td style="padding-left:10px;">
                <p> 
	                <input name="opointUse" id="opointUse" type="text"
	                 class="text-right" value="0"
	                size="10" oninput="chkPoint(this,'${mileage}')" >
	                 원 (사용가능 적립금 :<span style="color:red;font-weight:bold">${mileage}  원</span> 
	                 <input type="checkbox"
	                 onclick="useAllPoint('ㅁ')" >전부사용하기)
	                <input type="button" class="btn btn-success"
	                value="사용하기" 
	                onclick="" >				
                </p>                 
                <p>
					적립금은 최소 0 이상일 때 결제가 가능합니다.
                     최대 사용금액은 제한이 없습니다.1회 구매시 적립금 최대 사용금액은 입니다.<br>
                     적립금으로만 결제할 경우, 결제금액이 0으로 보여지는 것은 정상이며
                     <b>[결제하기]</b> 버튼을 누르면 주문이 완료됩니다.<br>
                    적립금 사용 시 배송비는 적립금으로 사용 할 수 없습니다.
                </p>
			   </td>
               </tr>
               </tbody>
            	</table>            
			</div>


<table class="table table-bordered">
	<tr>
		<th colspan="2">배송지 정보
		<input type="radio" name="info" id="uinfo1" value="1" checked>주문자 정보와 동일
		<input type="radio" name="info" id="uinfo2" value="2">새로운 수령자 정보
		</th>
	</tr>
	<tr>
		<td><b>주문자</b></td>
		<td class="text-left">${loginUser.name} [ ${loginUser.userid} ]</td>
	</tr>
	<tr>
		<td><b>수령자</b></td>
		<td class="text-left">
			<input type="text" name="name" value="${loginUser.name}">
		</td>
	</tr>
	<tr>
		<td><b>연락처</b></td>
		<td class="text-left">
			<input type="text" name="hp1"
				value="${loginUser.hp1}"  size="3"
				maxlength="3" />
			- <input type="text" name="hp2" value="${loginUser.hp2}"
			size="4" maxlength="4" />- <input type="text" name="hp3"
			value="${loginUser.hp3}" size="4" maxlength="4" /></td>
	</tr>
	
	<tr>
		<td><b>우편번호</b></td>
		<td class="text-left">
		<div class="col-md-3">
		<input type="text" name="zipcode" value="${loginUser.post}" class="form-control"  maxlength="5" /> 
		<div>
		<div class="col-md-3 text-left">
		<input
			type="button" value="검  색" class="btn btn-warning" />
		</div>	
			</td>

	</tr>
	<tr>
		<td><b>주소</b></td>
		<td class="text-left">
		<input type="text" name="addr1" value="${loginUser.addr1}" class="form-control" /></td>
	</tr>
	<tr>
		<td><b>나머지 주소</b></td>
		<td class="text-left">
		<input type="text" name="addr2" value="${loginUser.addr2}" class="form-control" /></td>
	</tr>
	
	<tr>
		<td><b>배송시 요청사항</b></td>
		<td class="text-left">
		<input type="text" name="ordermemo"
		  class="form-control" /></td>
	</tr>
	<!-- 결제수단 -->
	<tr>
		<td><b>결제방법</b></td>
		<td class="text-left">
			<input type="radio" name="opayWay" checked value="100" onclick="showSelect(this.value)">무통장입금
			<input type="radio" name="opayWay" value="200"  onclick="showSelect(this.value)">카드 결제
			
			<span id="c1">
				<select name="bank" id="bank">
					<option value="1">국민</option>
					<option value="2">우리</option>
					<option value="3">신한</option>
				</select>
			</span>
			<span id="c2" style="display:none">
				<select name="card" id="card">
					<option value="1">국민카드</option>
					<option value="2">BC카드</option>
					<option value="3">현대카드</option>
					<option value="4">농협카드</option>
				</select>
			</span>
			
		</td>
	</tr>
	
	<tr>
		<td colspan="2"><input type="submit" value="주문결제"
		 class="btn btn-success"/></td>
	</tr>
	
</table>

</form>
<!-- ============================ -->
<script type="text/javascript">
	$(function(){
		$('#card').prop("disabled", true);
		$('#bank').prop("disabled", false);
	});
	function chkPoint(input, mileage){
		var tmpPoint = parseInt(input.value);
		if(tmpPoint>mileage){
			alert("사용 가능한 적립금액 보다 많습니다.");
			input.value="0";
			return;
		}
	}//--------------------------
	
	function useAllPoint(mileage){
		
	}//---------------------------
	
	function calcToPrice(usePoint, totalBuy){
		
	}//---------------------------
	

	function showSelect(pay){
		//alert(pay);
		
		if(pay=='100'){//무통장 입금
			$('#c1').show();
			$('#c2').hide();
			$('#bank').prop("disabled", false);//은행이 서버로 넘어가도록
			$('#card').prop("disabled", true);
		}else if(pay=='200'){
			//카드결제
			$('#c1').hide();
			$('#c2').show();
			$('#card').prop("disabled", false);//카드가 서버로 넘어가도록
			$('#bank').prop("disabled", true);
		}
	}

	$(function(){
		$('#uinfo1').click(function(){
			custF.name.value="${loginUser.name}";
			custF.hp1.value="${loginUser.hp1}";
			custF.hp2.value="${loginUser.hp2}";
			custF.hp3.value="${loginUser.hp3}";
			custF.zipcode.value="${loginUser.post}";
			custF.addr1.value="${loginUser.addr1}";
			custF.addr2.value="${loginUser.addr2}";
		});
		
		$('#uinfo2').click(function(){
			custF.name.value="";
			custF.hp1.value="";
			custF.hp2.value="";
			custF.hp3.value="";
			custF.zipcode.value="";
			custF.addr1.value="";
			custF.addr2.value="";
		});
	});

	
</script>
</div>
</div>
<c:import url="/foot"/>

OrderVO

package com.tis.domain;

import java.sql.Date;
import java.util.List;

import lombok.Data;

@Data
public class OrderVO {
	//orderDesc관련 property
	private String onum;//주문번호
	private int idx_fk; //회원번호
	
	private int ototalPrice;//주문총액
	private int ototalPoint;//주문총포인트
	private String opayState;//지불상태(미결제, 결제완료, 결제취소)
	private String odeliver;//배송상태(배송전, 배송중, 배송완료)
	private int odeliverPrice;//배송비
	private Date orderDate;//주문날짜
	private String orderMemo;//요청사항
	private String opayWay;//지불방법(100:무통장 입금, 200:카드결제)
	private int opointUser;//사용포인트
	
	
	//orderProduct관련 property
	//OrderVO have Products
	private List<ProductVO> orderList;
	
	//receiver관련 property
	//OrderVO has Receiver
	private ReceiverVO receiver;//수령자 정보
	
	
}

OrderService

package com.tis.service;

import java.util.List;

import com.tis.domain.OrderVO;

//import com.tis.domain.OrderVO;

public interface OrderService {
	//주문개요 정보와 주문상품정보, 수령자 정보를 insert하는 메소드
	//주문자의 마일리지 적립금을 차감 또는 적립 처리
	String orderInsert(OrderVO ovo);
	
	//주문번호로 주문 내역정보를 가져오는 메소드
	List<OrderVO> getOrderDesc(String onum);
	
	//회원번호로 회원의 주문한 목록을 가져오는 메소드
	List<OrderVO> getUserOrderList(int idx_fk);

}

OrderServiceImpl

package com.tis.service;

import java.util.List;

import javax.inject.Inject;

import org.springframework.stereotype.Service;

import com.tis.domain.OrderVO;

@Service("orderServiceImpl")
public class OrderServiceImpl implements OrderService {
	@Inject
	private OrderMapper orderMapper;
	
	@Override
	public String orderInsert(OrderVO ovo) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<OrderVO> getOrderDesc(String onum) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<OrderVO> getUserOrderList(int idx_fk) {
		// TODO Auto-generated method stub
		return null;
	}

}

OrderMapper

package com.tis.mapper;

import java.util.List;

import com.tis.domain.OrderVO;
import com.tis.domain.ProductVO;

public interface OrderMapper {
	//주문 개요 정보 insert
	int orderDescInsert(OrderVO ovo);
	
	//주문상품 정보 insert
	int orderProductInsert(List<ProductVO> prod);
	
	//수령자 정보 insert
	int receiverInsert(OrderVO ovo);
	
	//주문 내역정보 가져오기
	List<OrderVO> getOrderDesc(String onum);
	
	//특정 회원의 주문내역 가져오기(mypage)
	List<OrderVO> getUserOrderList(int idx_fk);
}

+ Recent posts