일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 객체지향
- 자바문제
- servlet
- Error
- API
- 단축키
- JDBC
- nodejs
- 컬렉션프레임워크
- 자바
- ddit
- ibatis
- 이클립스
- Oracle
- FastAPI
- 맥
- spring
- 반복문
- Mac
- Homebrew
- Java
- Android
- 배열
- jsp
- html
- crud
- python
- 대덕인재개발원
- pyqt
- 생활코딩
Archives
- Today
- Total
romworld
JSP 10 - 쇼핑몰 사이트 만들기(3) [상품 상세 정보] 본문
상세보기
<ProductRepository.java>
에다가 상세보기 메소드를 추가한다.
//상품 상세 보기
// 리턴타입 : ProductVO 타입(1행)
// 요청 URI : /product.jsp?id=P1234
// 요청 URL : /product.jsp
// 요청 파라미터 : id=P1234(request객체에 들어있음)
// P1234 : 기본키 데이터(PRODUCT_ID-테이블컬럼. productId-ProductVO의 멤버변수)
// 기본키(Primary key) : Not Null, No Duplicate
public ProductVO getProductById(String productId) {
int size = this.listOfProducts.size(); // 3행
//1행을 찾았다면 넣어두자
//SELECT * FROM PRODUCT WHERE PRODUCT_ID = 'P1234';
ProductVO productVOById = null;
// i = 0, 1, 2
// List<ProductVO> => 1건 꺼내오면 => ProductVO 타입이 나옴
for(int i =0; i<size; i++) {
ProductVO productVO = listOfProducts.get(i);
// P1234 <- productId : 파라미터(선택된 데이터)
/*
SELECT PRODUCT_ID FROM PRODUCT;
productVo.getProductId() -> P1234..
productVo.getProductId() -> P1235..
productVo.getProductId() -> P1236..
*/
if(productVO.getProductId().equals(productId)) {
productVOById = productVO;
break;
}
}
return productVOById;
}
<product.jsp>
<%@page import="kr.or.ddit.vo.ProductVO"%>
<%@page import="kr.or.ddit.dao.ProductRepository"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!--fmt => format -->
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
//DAO(Data Access Object = > 데이터를 가져오는 객체)
ProductRepository productDAO = ProductRepository.getInstance();
%>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="/css/bootstrap.min.css">
<title>상품 상세 정보</title>
</head>
<body>
<!-- include 액션 태그 -->
<jsp:include page="menu.jsp" />
<!-- 상품 상세 시작 -->
<div class="jumbotron">
<!-- container : 이 안에 내용 있다. -->
<div class="container">
<h1 class="display-3">상품 정보</h1>
</div>
</div>
<%
//http://localhost/product.jsp?id=P1234
//id=P1234 요청파라미터는 request객체 안에 있음
//파라미터의 값의 타입은 String
String id = request.getParameter("id"); // P1234
// P1234의 기본키에 해당되는 상품 1행을 가져오자
//SELECT * FROM PRODUCT WHERE PRODUCT_ID = 'P1234'
ProductVO productVO = productDAO.getProductById(id);
%>
<c:set var="productVO" value="<%=productVO %>"/>
<!-- 내용 -->
<div class="container">
<!-- 1건의 상품. 1행 -->
<div class="row">
<div class="col-md-5">
<img src="/images/${productVO.filename}"
alt="${productVO.pname}" title="${productVO.pname}" style="width:100%" >
</div>
<!-- 6크기의 1열 div -->
<div class="col-md-6">
<h3>${productVO.pname}</h3>
<p><${productVO.description}</p>
<p>
<b>상품 코드 :</b>
<span class="badge badge-danger">
${productVO.productId}
</span>
</p>
<p><b>제조사 : ${productVO.manufacturer}</b></p>
<p><b>분 류 : ${productVO.category}</b></p>
<p><b>재고수 : ${productVO.unitsInStock}</b></p>
<h4>
<!-- c:set으로 자바에 있는 코드를 jsp 연결하는 방법도 있지만 이렇게 바로 자바코드를 사용해주는 방법도 있다 -->
<%-- <%=productVO.getUnitPrice() %> --%>
<fmt:formatNumber value="${productVO.unitPrice}"
type="currency" currencySymbol="₩"/> 원
</h4>
<p>
<form action="addCard.jsp?id=<%=productVO.getProductId() %>"
method="post">
<a href="#" class="btn btn-info">상품 주문»</a>
<a href="cart.jsp" class="btn btn-warning">장바구니»</a>
<a href="products.jsp" class="btn btn-secondary">상품 목록»</a>
</form>
</p>
</div>
</div>
</div>
<!-- 상품 상세 끝 -->
<jsp:include page="footer.jsp" />
</body>
</html>
'WEB > JSP' 카테고리의 다른 글
JSP - 12 함수 (map(), prop()) (0) | 2023.01.02 |
---|---|
JSP 10 - form 태그 (회원가입양식) (0) | 2022.12.29 |
JSP 09 - out (0) | 2022.12.28 |
JSP 08 - response (0) | 2022.12.28 |
JSP 07 - request (0) | 2022.12.28 |
Comments