JSP

 

 

 

OrderAllAction

package net.macaronics.web.controll;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.macaronics.web.controll.action.Action;
import net.macaronics.web.dao.OrderDAO;
import net.macaronics.web.dto.MemberVO;
import net.macaronics.web.dto.OrderVO;

public class OrderAllAction implements Action{

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		 String url="mypage/mypage.jsp";
		 
		 HttpSession session= request.getSession();
		 MemberVO loginUser=(MemberVO)session.getAttribute("loginUser");
		 
		 if(loginUser==null){
			 url="MacaronicsServlet?command=login_form";
		 }else{
			 OrderDAO orderDAO =OrderDAO.getInstance();
			 //중복을 제거한 주문 번호만 불러오기
			 //select distinct oseq from order_view where id=#{id} and result='1' order by oseq desc
			 List<Integer> oseqList=orderDAO.selectSeqOrdering(loginUser.getId());
			 //주문 목록 담기 객체 만들기
			 List<OrderVO> orderList=new ArrayList<>();
			 			 
			 for(int oseq: oseqList){
				 List<OrderVO> orderListing=orderDAO.listOrderById(loginUser.getId(),
						 "%", oseq);
				 
				 OrderVO orderVO=orderListing.get(0);
				 orderVO.setPname(orderVO.getPname() + " 외" + orderListing.size() + " 건");
				 
				 int totalPrice=0;
				 for(OrderVO ovo : orderListing){
					 totalPrice += ovo.getPrice2()* ovo.getQuantity();
				 }
				 orderVO.setPrice2(totalPrice);
				 orderList.add(orderVO);
			 }
			 request.setAttribute("title", "총 주문 내역");
			 request.setAttribute("orderList", orderList);
		 }
		 request.getRequestDispatcher(url).forward(request, response);
	}
	

	
}



 

 

	<select id="listOrderById" resultType="net.macaronics.web.dto.OrderVO">
		select * from order_view where id=#{id} and result like '%'||#{result} ||'%' and oseq=#{oseq}
	</select>


	<select id="selectSeqOrdering" resultType="int">
		select distinct oseq from order_view where id=#{id} and result='1' order by oseq desc
	</select>

 

 

 

 

 

제작 : macaronics.net - Developer  Jun Ho Choi

소스 :  https://github.com/braverokmc79/jsp_sin

 

${request.getContextPath() } 처리를 안한 부분이 있으므로 

루트 설정( http://macaronics.net/index.php/m01/jsp/view/1352)    및 server.xml  에서 DB 컨넥션 설정은 필수 설정이다.

 

about author

PHRASE

Level 60  라이트

Beauty is but [only] skin-deep. 미모는 거죽 한 꺼풀. (외모로 사람을 평가하지 말라).

댓글 ( 0)

댓글 남기기

작성