JSP
list.jsp
detail이동 추가
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<script type="text/javascript" src="/resources/js/jquery.min.js"></script>
<div class="row">
<div class="col-md-6 card" style="width: 45%">
<div class="card-header row" style="justify-content: space-between;">
<div>
<h3>상품 목록</h3>
</div>
<button type="button" class="btn btn-success" onclick="javascript:location.href='/prod/regist'">상품 등록</button>
</div>
<div class="card-body row" style="justify-content: space-between;">
<table class="table table-bordered">
<thead>
<tr>
<th>순번</th>
<th>상품명</th>
<th>판매가</th>
<th>거래처</th>
</tr>
</thead>
<c:choose>
<c:when test="${param.currentPage == null || param.currentPage == '1'}">
<c:set var="rowNumber" value="0"/>
</c:when>
<c:otherwise>
<c:set var="rowNumber" value="${(param.currentPage-1) * 10}"/> <!-- 다른 페이지에 대한 로직 -->
</c:otherwise>
</c:choose>
<tbody id="prodTable">
<c:forEach var="buyer" items="${data.content}">
<c:forEach var="prod" items="${buyer.prodVoList}">
<tr class="click" data-prod-id="${prod.prodId}">
<td>${rowNumber + 1}</td>
<td>${prod.prodName}<a href="/prod/detail?prodId=${prod.prodId}" class="badge bg-primary" title="${prod.prodName}">상세보기</a></td>
<td><fmt:formatNumber value="${prod.prodSale}" pattern="#,###" type="number"/></td>
<td>${buyer.buyerName}</td>
</tr>
<c:set var="rowNumber" value="${rowNumber + 1}"/>
</c:forEach>
</c:forEach>
</tbody>
</table>
<div class="card-footer clearfix" style="width: 100%">${data.pagingArea}</div>
</div>
</div>
<div class="col-md-6 card" style="width: 45%">
<div class="card-header">
<h3>상품 별 장바구니 목록 현황</h3>
</div>
<div class="card-body">
<table class="table table-bordered">
<thead>
<tr>
<th>순번</th>
<th>일자</th>
<th>수량</th>
<th>회원 아이디</th>
<th>회원명</th>
</tr>
</thead>
<tbody id="cartlist">
<tr>
<td colspan="5">상품을 선택해주세요</td>
</tr>
</tbody>
</table>
<div class="right">
<input type="button" class="btn btn-primary" value="장바구니 관리" id="cart" onclick="javascript:location.href='/prod/cart'">
</div>
</div>
</div>
</div>
<div class="modal fade" id="modal-mem">
<div class="modal-dialog modal-mem">
<div class="modal-content">
<!-- Horizontal Form -->
<form class="form-horizontal">
<div class="card card-info">
<div class="card-header">
<h3 class="card-title">회원 정보</h3>
</div>
<!-- /.card-header -->
<!-- form start -->
<div class="card-body">
<div class="form-group row">
<label for="memId" class="col-sm-2 col-form-label">아이디</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="memId" readonly>
</div>
</div>
<div class="form-group row">
<label for="memName" class="col-sm-2 col-form-label">이름</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="memName" readonly>
</div>
</div>
<div class="form-group row">
<label for="exampleInputPassword1" class="col-sm-2 col-form-label">생일</label>
<div class="col-sm-10">
<input type="date" class="form-control" id="memBir" name="memBir" readonly />
</div>
</div>
<div class="form-group row">
<label for="exampleInputPassword1" class="col-sm-2 col-form-label">우편</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="memZip" name="memZip" readonly />
</div>
</div>
<div class="form-group row">
<label for="memAdd" class="col-sm-2 col-form-label">주소</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="memAdd" readonly>
</div>
</div>
<div class="form-group row">
<label for="memHp" class="col-sm-2 col-form-label">핸드폰</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="memHp" readonly>
</div>
</div>
<div class="form-group row">
<label for="memMail" class="col-sm-2 col-form-label">이메일</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="memMail" readonly>
</div>
</div>
</div>
<!-- /.card-body -->
<div class="card-footer">
<button type="submit" class="btn btn-info">확인</button>
<button type="submit" class="btn btn-default float-right">취소</button>
</div>
<!-- /.card-footer -->
</div>
<!-- /.card -->
</form>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
<!-- /.modal -->
<script>
$(function(){
$('.click').on('click',function(){
$('#prodTable tr').css({"background": "white", "color":"black"});
$(this).css({"background": "#007bff", "color":"white"});
let prodId = $(this).data("prodId");
$.ajax({
url : "/prod/listAjax",
data : JSON.stringify({"prodId" : prodId}),
contentType : 'application/json',
dataType : "json",
type : "post",
success : function(res){
let str = "";
if(typeof res[0] == "undefined"){
str="<tr><td colspan='5'>장바구니 담은 회원이 없습니다<td></tr>";
$('#cartlist').html(str);
return false;
}
console.log(res[0]);
let indx = 1;
$.each(res[0].cartVoList, function(i, vo){
str += "<tr class='member' data-toggle='modal' data-target='#modal-mem' data-mem-id='"+vo.cartMember+"'> <td>"+ indx++ +"</td>";
str += "<td>"+ vo.cartNo.substring(0,4)+"-"+vo.cartNo.substring(4,6)+"-"+vo.cartNo.substring(6,8) +"</td>";
str += "<td>"+ vo.cartQty +"</td>";
str += "<td>"+ vo.cartMember +"</td>";
str += "<td>"+ vo.memVo.memName +"</td></tr>";
})
$('#cartlist').html(str);
}
})
})
$(document).on('click','.member',function(){
let memId = $(this).data("memId");
$.ajax({
url : "/prod/memInfo",
data : JSON.stringify({"memId" : memId}),
contentType : 'application/json',
dataType : "json",
type : "post",
success : function(res){
console.log(res);
let str = "";
$('#memId').val(res.memId);
$('#memName').val(res.memName);
$('#memZip').val(res.memZip);
$('#memBir').val(res.memBirStr);
$('#memHp').val(res.memHp);
$('#memAdd').val(res.memAdd1+" "+res.memAdd2);
$('#memMail').val(res.memMail);
}
})
})
})
</script>
detail.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<script type="text/javascript" src="/resources/js/jquery.min.js"></script>
<!-- Default box -->
<div class="card card-solid">
<div class="card-body">
<div class="row">
<div class="col-12 col-sm-6">
<c:set var="prod" value="${buyer.prodVoList[0]}"/>
<h3 class="d-inline-block d-sm-none">${prod.prodName}</h3>
<div class="col-12">
<c:if test="${prod.fgvo.fileDetailVoList==null}">
<img src="/resources/images/noimage.jpg" class="product-image" alt="Product Image">
</c:if>
<c:if test="${prod.fgvo.fileDetailVoList!=null}">
<img src="${prod.fgvo.fileDetailVoList[0].fileSaveLocate}" class="product-image" alt="Product Image">
</c:if>
</div>
<div class="col-12 product-image-thumbs">
<c:forEach var="img" items="${prod.fgvo.fileDetailVoList}">
<div class="product-image-thumb" ><img src="${img.fileSaveLocate}" alt="Product Image" style="width: 100px"></div>
</c:forEach>
</div>
</div>
<div class="col-12 col-sm-6">
<h3 class="my-3">${prod.prodName}</h3>
<p>${buyer.buyerName}</p>
<hr>
${prod.prodOutline}
<!-- <h4>Available Colors</h4> -->
<!-- <div class="btn-group btn-group-toggle" data-toggle="buttons"> -->
<!-- <label class="btn btn-default text-center active"> -->
<!-- <input type="radio" name="color_option" id="color_option_a1" autocomplete="off" checked> -->
<!-- Green -->
<!-- <br> -->
<!-- <i class="fas fa-circle fa-2x text-green"></i> -->
<!-- </label> -->
<!-- <label class="btn btn-default text-center"> -->
<!-- <input type="radio" name="color_option" id="color_option_a2" autocomplete="off"> -->
<!-- Blue -->
<!-- <br> -->
<!-- <i class="fas fa-circle fa-2x text-blue"></i> -->
<!-- </label> -->
<!-- <label class="btn btn-default text-center"> -->
<!-- <input type="radio" name="color_option" id="color_option_a3" autocomplete="off"> -->
<!-- Purple -->
<!-- <br> -->
<!-- <i class="fas fa-circle fa-2x text-purple"></i> -->
<!-- </label> -->
<!-- <label class="btn btn-default text-center"> -->
<!-- <input type="radio" name="color_option" id="color_option_a4" autocomplete="off"> -->
<!-- Red -->
<!-- <br> -->
<!-- <i class="fas fa-circle fa-2x text-red"></i> -->
<!-- </label> -->
<!-- <label class="btn btn-default text-center"> -->
<!-- <input type="radio" name="color_option" id="color_option_a5" autocomplete="off"> -->
<!-- Orange -->
<!-- <br> -->
<!-- <i class="fas fa-circle fa-2x text-orange"></i> -->
<!-- </label> -->
<!-- </div> -->
<!-- <h4 class="mt-3">Size <small>Please select one</small></h4> -->
<!-- <div class="btn-group btn-group-toggle" data-toggle="buttons"> -->
<!-- <label class="btn btn-default text-center"> -->
<!-- <input type="radio" name="color_option" id="color_option_b1" autocomplete="off"> -->
<!-- <span class="text-xl">S</span> -->
<!-- <br> -->
<!-- Small -->
<!-- </label> -->
<!-- <label class="btn btn-default text-center"> -->
<!-- <input type="radio" name="color_option" id="color_option_b2" autocomplete="off"> -->
<!-- <span class="text-xl">M</span> -->
<!-- <br> -->
<!-- Medium -->
<!-- </label> -->
<!-- <label class="btn btn-default text-center"> -->
<!-- <input type="radio" name="color_option" id="color_option_b3" autocomplete="off"> -->
<!-- <span class="text-xl">L</span> -->
<!-- <br> -->
<!-- Large -->
<!-- </label> -->
<!-- <label class="btn btn-default text-center"> -->
<!-- <input type="radio" name="color_option" id="color_option_b4" autocomplete="off"> -->
<!-- <span class="text-xl">XL</span> -->
<!-- <br> -->
<!-- Xtra-Large -->
<!-- </label> -->
<!-- </div> -->
<div class="bg-gray py-2 px-3 mt-4">
<h2 class="mb-0">
<fmt:formatNumber value="${prod.prodSale}" pattern="#,###" type="number"/> 원
</h2>
</div>
<!-- <div class="mt-4"> -->
<!-- <div class="btn btn-primary btn-lg btn-flat"> -->
<!-- <i class="fas fa-cart-plus fa-lg mr-2"></i> -->
<!-- Add to Cart -->
<!-- </div> -->
<!-- <div class="btn btn-default btn-lg btn-flat"> -->
<!-- <i class="fas fa-heart fa-lg mr-2"></i> -->
<!-- Add to Wishlist -->
<!-- </div> -->
<!-- </div> -->
<button type="button" onclick="javascript:location.href='/prod/list'" class="btn btn-default btn-lg btn-flat">
목록으로 돌아가기
</button>
<div class="mt-4 product-share">
<a href="#" class="text-gray">
<i class="fab fa-facebook-square fa-2x"></i>
</a>
<a href="#" class="text-gray">
<i class="fab fa-twitter-square fa-2x"></i>
</a>
<a href="#" class="text-gray">
<i class="fas fa-envelope-square fa-2x"></i>
</a>
<a href="#" class="text-gray">
<i class="fas fa-rss-square fa-2x"></i>
</a>
</div>
</div>
</div>
<div class="row mt-4">
<nav class="w-100">
<div class="nav nav-tabs" id="product-tab" role="tablist">
<a class="nav-item nav-link active" id="product-desc-tab" data-toggle="tab" href="#product-desc" role="tab" aria-controls="product-desc" aria-selected="true">Description</a>
<a class="nav-item nav-link" id="product-comments-tab" data-toggle="tab" href="#product-comments" role="tab" aria-controls="product-comments" aria-selected="false">Comments</a>
<a class="nav-item nav-link" id="product-rating-tab" data-toggle="tab" href="#product-rating" role="tab" aria-controls="product-rating" aria-selected="false">Rating</a>
</div>
</nav>
<div class="tab-content p-3" id="nav-tabContent">
<div class="tab-pane fade show active" id="product-desc" role="tabpanel" aria-labelledby="product-desc-tab">
${prod.prodDetail}
</div>
<div class="tab-pane fade" id="product-comments" role="tabpanel" aria-labelledby="product-comments-tab"> Vivamus rhoncus nisl sed venenatis luctus. Sed condimentum risus ut tortor feugiat laoreet. Suspendisse potenti. Donec et finibus sem, ut commodo lectus. Cras eget neque dignissim, placerat orci interdum, venenatis odio. Nulla turpis elit, consequat eu eros ac, consectetur fringilla urna. Duis gravida ex pulvinar mauris ornare, eget porttitor enim vulputate. Mauris hendrerit, massa nec aliquam cursus, ex elit euismod lorem, vehicula rhoncus nisl dui sit amet eros. Nulla turpis lorem, dignissim a sapien eget, ultrices venenatis dolor. Curabitur vel turpis at magna elementum hendrerit vel id dui. Curabitur a ex ullamcorper, ornare velit vel, tincidunt ipsum. </div>
<div class="tab-pane fade" id="product-rating" role="tabpanel" aria-labelledby="product-rating-tab"> Cras ut ipsum ornare, aliquam ipsum non, posuere elit. In hac habitasse platea dictumst. Aenean elementum leo augue, id fermentum risus efficitur vel. Nulla iaculis malesuada scelerisque. Praesent vel ipsum felis. Ut molestie, purus aliquam placerat sollicitudin, mi ligula euismod neque, non bibendum nibh neque et erat. Etiam dignissim aliquam ligula, aliquet feugiat nibh rhoncus ut. Aliquam efficitur lacinia lacinia. Morbi ac molestie lectus, vitae hendrerit nisl. Nullam metus odio, malesuada in vehicula at, consectetur nec justo. Quisque suscipit odio velit, at accumsan urna vestibulum a. Proin dictum, urna ut varius consectetur, sapien justo porta lectus, at mollis nisi orci et nulla. Donec pellentesque tortor vel nisl commodo ullamcorper. Donec varius massa at semper posuere. Integer finibus orci vitae vehicula placerat. </div>
</div>
</div>
</div>
<!-- /.card-body -->
</div>
<!-- /.card -->
<script>
$(document).ready(function() {
$('.product-image-thumb').on('click', function () {
var $image_element = $(this).find('img')
$('.product-image').prop('src', $image_element.attr('src'))
$('.product-image-thumb.active').removeClass('active')
$(this).addClass('active')
})
})
</script>
JAVA
ProdVO.java
package kr.or.ddit.vo;
import java.util.Date;
import java.util.List;
import org.springframework.web.multipart.MultipartFile;
import lombok.Data;
@Data
public class ProdVO {
private int rnum;
private String prodId;
private String prodName;
private String prodLgu;
private String prodBuyer;
private int prodCost;
private int prodPrice;
private int prodSale;
private String prodOu;
private String prodDetail;
private String prodImg;
private int prodTotalstock;
private Date prodInsdate;
private String prodOutline;
private int prodProperstock;
private String prodSize;
private String prodColor;
private String prodDelivery;
private String prodUnit;
private int prodQtyin;
private int prodQtysale;
private int prodMileage;
private long fileGroupNo;
private MultipartFile[] uploadFile;
private List<CartVO> cartVoList;
private FileGroupVO fgvo;
}
ProdController.java
package kr.or.ddit.controller;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import kr.or.ddit.service.ProdService;
import kr.or.ddit.util.ArticlePage;
import kr.or.ddit.vo.BuyerVO;
import kr.or.ddit.vo.LprodVO;
import kr.or.ddit.vo.MemberVO;
import kr.or.ddit.vo.ProdVO;
import kr.or.ddit.vo.TblUserVO;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@RequestMapping("/prod")
@Controller
public class ProdController {
@Autowired
ProdService service;
@ModelAttribute
public void prodInit(Model model) {
model.addAttribute("title", "상품 정보");
}
@GetMapping("/list")
public String list(Model model, @RequestParam(value="currentPage", required = false, defaultValue = "1") int currentPage) {
Map<String, Object> map = new HashMap<>();
int size = 10;
int total = this.service.getTotal();
map.put("currentPage", currentPage);
map.put("size", size);
List<ProdVO> list = this.service.list(map);
map.clear();
// model.addAttribute("data", list);
model.addAttribute("data", new ArticlePage<ProdVO>(total, currentPage, size, list, map));
return "prod/list";
}
@ResponseBody
@PostMapping("/listAjax")
public List<ProdVO> listAjax(@RequestBody ProdVO vo){
List<ProdVO> list = this.service.cartlist(vo);
return list;
}
@ResponseBody
@PostMapping("/memInfo")
public MemberVO memDetail(@RequestBody MemberVO vo) {
vo = this.service.memDetail(vo);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String datestr = sdf.format(vo.getMemBir());
vo.setMemBirStr(datestr);
return vo;
}
@GetMapping("/cart")
public String cart(Model model) {
return "prod/cart";
}
@ResponseBody
@GetMapping("/prodlist")
public ArticlePage<ProdVO> prodList(Model model, @RequestParam(value="currentPage", required = false, defaultValue = "1") int currentPage) {
Map<String, Object> map = new HashMap<>();
int size = 10;
int total = this.service.getTotal();
map.put("currentPage", currentPage);
map.put("size", size);
List<ProdVO> list = this.service.list(map);
map.clear();
ArticlePage<ProdVO> art = new ArticlePage<ProdVO>(total, currentPage, size, list, map);
return art;
}
@GetMapping("/cardForm")
public String cardForm(Model model) {
// 카드번호 자동 생성
List<String> cardRndNo = new ArrayList<String>();
for(int i=0; i<3; i++) {
Random rand = new Random();
cardRndNo.add(""+rand.nextInt(1000000000));
}
model.addAttribute("cardList", cardRndNo);
return "prod/cardForm";
}
@ResponseBody
@PostMapping("/cardFormPost")
public TblUserVO cardFormPost (TblUserVO vo) {
log.info("vo "+vo);
int result = this.service.cardFormPost(vo);
log.info("result "+result);
return vo;
}
@GetMapping("/regist")
public String regist(Model model) {
List<LprodVO> lprod = this.service.lprodList();
model.addAttribute("lprod",lprod);
return "prod/regist";
}
@ResponseBody
@PostMapping("/buyer")
public List<BuyerVO> buyerList(@RequestBody BuyerVO vo) {
List<BuyerVO> buyer = this.service.buyerList(vo);
return buyer;
}
@ResponseBody
@PostMapping("/createProdId")
public String createProdId(@RequestBody ProdVO vo) {
log.info("vo >>"+vo);
String prodId = this.service.createProdId(vo);
log.info("id >>"+prodId);
return prodId;
}
@PostMapping("/registPost")
public String registPost(ProdVO prodVo) {
log.info("vo >>"+prodVo);
int result = this.service.registPost(prodVo);
log.info("result >> "+result);
// return "redirect: /prod/list";
return "redirect: /prod/detail?prodId="+prodVo.getProdId();
}
@GetMapping("/detail")
public String detail(@RequestParam("prodId") String prodId, Model model) {
ProdVO prodVo = new ProdVO();
prodVo.setProdId(prodId);
log.info("vo >>"+prodVo);
BuyerVO buyer = this.service.detail(prodVo);
log.info("vo >>"+buyer);
model.addAttribute("buyer", buyer);
return "prod/detail";
}
}
ProdService.java
package kr.or.ddit.service;
import java.util.List;
import java.util.Map;
import kr.or.ddit.vo.BuyerVO;
import kr.or.ddit.vo.LprodVO;
import kr.or.ddit.vo.MemberVO;
import kr.or.ddit.vo.ProdVO;
import kr.or.ddit.vo.TblUserVO;
public interface ProdService{
public List<ProdVO> list(Map<String, Object> map);
public int getTotal();
public List<ProdVO> cartlist(ProdVO vo);
public MemberVO memDetail(MemberVO vo);
public int cardFormPost(TblUserVO vo);
public List<LprodVO> lprodList();
public List<BuyerVO> buyerList(BuyerVO bvo);
public String createProdId(ProdVO vo);
public int registPost(ProdVO vo);
public BuyerVO detail(ProdVO prodVo);
}
ProdServiceImpl.java
package kr.or.ddit.service.impl;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import kr.or.ddit.dao.ProdDao;
import kr.or.ddit.mapper.FileGroupMapper;
import kr.or.ddit.mapper.ProdMapper;
import kr.or.ddit.service.ProdService;
import kr.or.ddit.vo.BuyerVO;
import kr.or.ddit.vo.CardVO;
import kr.or.ddit.vo.CarsVO;
import kr.or.ddit.vo.FileDetailVO;
import kr.or.ddit.vo.FileGroupVO;
import kr.or.ddit.vo.LprodVO;
import kr.or.ddit.vo.MemberVO;
import kr.or.ddit.vo.ProdVO;
import kr.or.ddit.vo.TblHobbyVO;
import kr.or.ddit.vo.TblUserVO;
@Service
public class ProdServiceImpl implements ProdService{
@Autowired
ProdMapper mapper;
@Autowired
String uploadPath;
@Autowired
FileGroupMapper fileMapper;
@Override
public List<ProdVO> list(Map<String,Object> map) {
return this.mapper.prodList(map);
}
@Override
public int getTotal() {
return this.mapper.prodListTotal();
}
@Override
public List<ProdVO> cartlist(ProdVO vo) {
return this.mapper.cartlist(vo);
}
@Override
public MemberVO memDetail(MemberVO vo) {
return this.mapper.memDetail(vo);
}
@Override
public int cardFormPost(TblUserVO vo) {
// 1) tbl_user 테이블 insert
int result = this.mapper.insertTblUser(vo);
// 2) card 테이블에 insert
List<CardVO> cardvo = vo.getCardVoList();
String userId = vo.getUserId();
for(CardVO v : cardvo) {
v.setUserId(userId);
result+= this.mapper.insertCard(v);
}
// 3) hobby에 insert
List<TblHobbyVO> hobbyvo = new ArrayList<TblHobbyVO>();
String[] hobby = vo.getHobby(); // hobby 배열을 사용
// String[] hobby = vo.getHobbyStr().split(","); // hobbyStr을 활용
if(hobby!=null) {
for(String h: hobby) {
TblHobbyVO hvo = new TblHobbyVO();
hvo.setUserId(userId);
hvo.setHobby(h);
hobbyvo.add(hvo);
result+= this.mapper.insertHobby(hvo);
}
}
// 4) cars에 insert
List<CarsVO> carsVoList = new ArrayList<CarsVO>();
String[] cars = vo.getCars();
for(String car: cars) {
CarsVO cvo = new CarsVO();
cvo.setUserId(userId);
cvo.setCar(car);
carsVoList.add(cvo);
}
result+=this.mapper.insertCars(carsVoList);
return result;
}
@Override
public List<LprodVO> lprodList() {
return this.mapper.lprodList();
}
@Override
public List<BuyerVO> buyerList(BuyerVO bvo) {
return this.mapper.buyerList(bvo);
}
@Override
public String createProdId(ProdVO vo) {
return this.mapper.createProdId(vo);
}
@Override
public int registPost(ProdVO vo) {
int result = 0;
MultipartFile[] files = vo.getUploadFile();
if(files.length !=0) {
FileGroupVO fgvo = new FileGroupVO();
result += this.fileMapper.insertFileGroup(fgvo);
int i=1;
for(MultipartFile file : files) {
FileDetailVO fdvo = new FileDetailVO();
String ext = file.getOriginalFilename();
ext = ext.substring(ext.lastIndexOf("."));
String fileName = vo.getProdId()+"_"+ i +ext;
File uploadFolder = new File(this.uploadPath, getFolder());
if (!uploadFolder.exists()) {
uploadFolder.mkdirs();
}
File uploadFile = new File(uploadFolder, fileName);
try {
file.transferTo(uploadFile);
} catch (Exception e) {
e.getMessage();
}
long size = file.getSize();
String contentType = file.getContentType();
fdvo.setFileSn(i++);
fdvo.setFileGroupNo(fgvo.getFileGroupNo());
fdvo.setFileOriginalName(file.getOriginalFilename());
fdvo.setFileSaveName(fileName);
fdvo.setFileSaveLocate("/upload/"+getFolder().replace("\\", "/")+"/"+fileName); // 웹경로+uuid_파일명
fdvo.setFileSize(size);
fdvo.setFileExt(ext);
fdvo.setFileMime(contentType);
// 팬시 크기
fdvo.setFileFancysize("0");
result+= this.fileMapper.insertFileDetail(fdvo);
}
vo.setFileGroupNo(fgvo.getFileGroupNo());
}
result += this.mapper.registPost(vo);
return result;
}
// 연 / 월 / 일 폴더 생성
public String getFolder() {
// 2024-08-06 형식(format)지정
// 간단한 날짜 형식
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date today = new Date();
String str = sdf.format(today);
// 2024-08-06 > 2024\\08\\06
return str.replace("-", File.separator);
}
@Override
public BuyerVO detail(ProdVO prodVo) {
return this.mapper.detail(prodVo);
}
}
ProdMapper.java
package kr.or.ddit.mapper;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Mapper;
import kr.or.ddit.vo.BuyerVO;
import kr.or.ddit.vo.CardVO;
import kr.or.ddit.vo.CarsVO;
import kr.or.ddit.vo.LprodVO;
import kr.or.ddit.vo.MemberVO;
import kr.or.ddit.vo.ProdVO;
import kr.or.ddit.vo.TblHobbyVO;
import kr.or.ddit.vo.TblUserVO;
@Mapper
public interface ProdMapper {
public List<ProdVO> prodList(Map<String, Object> map);
public int prodListTotal();
public List<ProdVO> cartlist(ProdVO vo);
public MemberVO memDetail(MemberVO vo);
public int insertTblUser(TblUserVO vo);
public int insertCard(CardVO v);
public int insertHobby(TblHobbyVO hvo);
public int insertCars(List<CarsVO> carsVoList);
public List<LprodVO> lprodList();
public List<BuyerVO> buyerList(BuyerVO bvo);
public String createProdId(ProdVO vo);
public int registPost(ProdVO vo);
public BuyerVO detail(ProdVO vo);
}
Mybatis
prod_SQL.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="kr.or.ddit.mapper.ProdMapper">
<resultMap type="buyerVo" id="buyerMap">
<result property="buyerId" column="BUYER_ID"/>
<result property="buyerName" column="BUYER_NAME"/>
<result property="buyerLgu" column="BUYER_LGU"/>
<result property="buyerBank" column="BUYER_BANK"/>
<result property="buyerBankno" column="BUYER_BANKNO"/>
<result property="buyerBankname" column="BUYER_BANKNAME"/>
<result property="buyerZip" column="BUYER_ZIP"/>
<result property="buyerAdd1" column="BUYER_ADD1"/>
<result property="buyerAdd2" column="BUYER_ADD2"/>
<result property="buyerComtel" column="BUYER_COMTEL"/>
<result property="buyerFax" column="BUYER_FAX"/>
<result property="buyerMail" column="BUYER_MAIL"/>
<result property="buyerCharger" column="BUYER_CHARGER"/>
<result property="buyerTelext" column="BUYER_TELEXT"/>
<collection property="prodVoList" resultMap="prodMap"></collection>
</resultMap>
<resultMap type="prodVo" id="prodMap">
<result property="rnum" column="RNUM"/>
<result property="prodId" column="PROD_ID"/>
<result property="prodName" column="PROD_NAME"/>
<result property="prodLgu" column="PROD_LGU"/>
<result property="prodBuyer" column="PROD_BUYER"/>
<result property="prodCost" column="PROD_COST"/>
<result property="prodPrice" column="PROD_PRICE"/>
<result property="prodSale" column="PROD_SALE"/>
<result property="prodOutline" column="PROD_OUTLINE"/>
<result property="prodDetail" column="PROD_DETAIL"/>
<result property="prodImg" column="PROD_IMG"/>
<result property="prodTotalstock" column="PROD_TOTALSTOCK"/>
<result property="prodInsdate" column="PROD_INSDATE"/>
<result property="prodProperstock" column="PROD_PROPERSTOCK"/>
<result property="prodSize" column="PROD_SIZE"/>
<result property="prodColor" column="PROD_COLOR"/>
<result property="prodDelivery" column="PROD_DELIVERY"/>
<result property="prodUnit" column="PROD_UNIT"/>
<result property="prodQtyin" column="PROD_QTYIN"/>
<result property="prodQtysale" column="PROD_QTYSALE"/>
<result property="prodMileage" column="PROD_MILEAGE"/>
<association property="fgvo" resultMap="fileGroupMap"/>
<collection property="cartVoList" resultMap="cartMap"/>
</resultMap>
<resultMap type="fileGroupVo" id="fileGroupMap">
<result property="fileGroupNo" column="FILE_GROUP_NO"/>
<result property="fileRegdate" column="FILE_REGDATE"/>
<association property="fileDetailVoList" resultMap="fileDetailMap"></association>
</resultMap>
<resultMap type="fileDetailVo" id="fileDetailMap">
<result property="fileSn" column="FILE_SN"/>
<result property="fileGroupNo" column="FILE_GROUP_NO"/>
<result property="fileOriginalName" column="FILE_ORIGINAL_NAME"/>
<result property="fileSaveName" column="FILE_SAVE_NAME"/>
<result property="fileSaveLocate" column="FILE_SAVE_LOCATE"/>
<result property="fileSize" column="FILE_SIZE"/>
<result property="fileExt" column="FILE_EXT"/>
<result property="fileMime" column="FILE_MIME"/>
<result property="fileFancysize" column="FILE_FANCYSIZE"/>
<result property="fileSaveDate" column="FILE_SAVE_DATE"/>
<result property="fileDowncount" column="FILE_DOWNCOUNT"/>
</resultMap>
<resultMap type="cartVo" id="cartMap">
<result property="cartProd" column="CART_PROD"/>
<result property="cartQty" column="CART_QTY"/>
<result property="cartMember" column="CART_MEMBER"/>
<result property="cartNo" column="CART_NO"/>
<collection property="memVo" resultMap="memMap"></collection>
</resultMap>
<resultMap type="memVo" id="memMap">
<result property="memId" column="MEM_ID"/>
<result property="memPass" column="MEM_PASS"/>
<result property="memName" column="MEM_NAME"/>
<result property="memRegno1" column="MEM_REGNO1"/>
<result property="memRegno2" column="MEM_REGNO2"/>
<result property="memBir" column="MEM_BIR"/>
<result property="memZip" column="MEM_ZIP"/>
<result property="memAdd1" column="MEM_ADD1"/>
<result property="memAdd2" column="MEM_ADD2"/>
<result property="memHometel" column="MEM_HOMETEL"/>
<result property="memComtel" column="MEM_COMTEL"/>
<result property="memHp" column="MEM_HP"/>
<result property="memMail" column="MEM_MAIL"/>
<result property="memJob" column="MEM_JOB"/>
<result property="memLike" column="MEM_LIKE"/>
<result property="memMemorial" column="MEM_MEMORIAL"/>
<result property="memMemorialday" column="MEM_MEMORIALDAY"/>
<result property="memMileage" column="MEM_MILEAGE"/>
<result property="memDelete" column="MEM_DELETE"/>
</resultMap>
<select id="prodList" resultMap="buyerMap" parameterType="hashMap">
WITH t AS (
SELECT
ROW_NUMBER() OVER (ORDER BY a.prod_id) AS rnum,
A.PROD_ID,
A.PROD_NAME,
A.PROD_BUYER,
A.PROD_SALE,
A.PROD_OUTLINE,
A.PROD_DETAIL,
B.BUYER_ID,
B.BUYER_NAME
FROM
BUYER B
JOIN PROD A ON B.BUYER_ID = A.PROD_BUYER
)
SELECT
t.*
FROM
t
WHERE
t.rnum BETWEEN ((#{currentPage} - 1) * #{size}) + 1 AND #{currentPage} * #{size}
</select>
<select id="prodListTotal" resultType="int">
SELECT count(*)
FROM BUYER B, PROD A
WHERE B.BUYER_ID = A.PROD_BUYER
</select>
<select id="cartlist" resultMap="prodMap" parameterType="prodVo">
select
c.cart_no, c.cart_prod, p.prod_name, c.cart_qty, p.prod_sale, c.cart_member, m.mem_name
from prod p
inner join cart c on c.cart_prod=p.prod_id
inner join member m on c.cart_member = m.mem_id
where c.cart_prod = #{prodId}
</select>
<select id="memDetail" parameterType="memVo" resultType="memVo">
select *
from member
where mem_id=#{memId}
</select>
<insert id="insertTblUser" parameterType="tblUserVo">
insert into tbl_user(USER_ID,PASSWORD,NAME,EMAIL,BIR,ZIPCODE,ADDR,ADDRDET)
values(#{userId},#{password},#{name},#{email},#{bir},#{zipcode},#{addr},#{addrdet})
</insert>
<insert id="insertCard" parameterType="cardVo">
insert into card(CARD_NO,CARD_YM,USER_ID)
values(#{cardNo},#{cardYm},#{userId})
</insert>
<insert id="insertHobby" parameterType="tblHobbyVo">
insert into tbl_hobby(user_id, hobby)
values(#{userId}, #{hobby})
</insert>
<!-- <insert id="insertCars" parameterType="carsVo"> -->
<!-- INSERT ALL -->
<!-- <foreach collection="list" item="item"> -->
<!-- INTO cars(user_id, car) VALUES (#{item.userId}, #{item.car}) -->
<!-- </foreach> -->
<!-- SELECT * FROM dual -->
<!-- </insert> -->
<update id="insertCars" parameterType="java.util.List">
<foreach collection="list" item="item" open="INSERT ALL" close="SELECT * FROM DUAL" separator=" " index="idx">
INTO cars(user_id, car) VALUES (#{item.userId}, #{item.car})
</foreach>
</update>
<select id="lprodList" resultType="LprodVo">
select *
from lprod
</select>
<select id="buyerList" resultType="buyerVo" parameterType="buyerVo">
select *
from buyer
where buyer_lgu=#{buyerLgu}
</select>
<select id="createProdId" parameterType="prodVo" resultType="String">
select 'P'||(substr(nvl(max(prod_id),#{prodLgu}||'000000'),2)+1)
from prod
where prod_lgu=#{prodLgu}
</select>
<insert id="registPost" parameterType="prodVo">
insert into prod(prod_id,prod_name,prod_lgu,prod_buyer,prod_sale,file_group_no
<if test="prodDetail!=null">,prod_detail</if>
)
values(#{prodId},#{prodName},#{prodLgu},#{prodBuyer},#{prodSale},#{fileGroupNo}
<if test="prodDetail!=null">,#{prodDetail}</if>
)
</insert>
<select id="detail" parameterType="prodVo" resultMap="buyerMap">
select *
from prod a
inner join buyer d on d.buyer_id=a.prod_buyer
left outer join file_group b on a.file_group_no=b.file_group_no
left outer join file_detail c on b.file_group_no=c.file_group_no
where a.prod_id=#{prodId}
</select>
</mapper>