해당 포스트에서 다뤘던 prod에서 DAO를 mapper로 변경과 상품 추가 생성
JSP
list.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>
<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}</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 = "";
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>
regist.jsp
buyerID와 prodId는 prodLgu에 의해 결정되므로
prodLgu가 선택이 되면 변경되도록 javascript로 비동기화 처리
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<link type="text/css" href="/resources/ckeditor5/sample/css/sample.css" rel="stylesheet" media="screen"/>
<script type="text/javascript" src="/resources/ckeditor5/ckeditor.js"></script>
<script type="text/javascript" src="/resources/js/jquery.min.js"></script>
<div class="card card-success">
<div class="card-header">
<h2>상품 등록</h2>
</div>
<form id="frm" action="/prod/registPost" method="post" enctype="multipart/form-data">
<div class="card-body">
<div class="row">
<div class="col-sm-6">
<!-- text input -->
<div class="form-group">
<label for="prodId">상품 코드</label> <input required type="text"
class="form-control" readonly placeholder="상품분류를 선택해주세요"
name="prodId" id="prodId">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="prodLgu">상품 분류 코드</label> <select required="required" class="form-control"
id="prodLgu" name="prodLgu">
<option value="" selected="selected" disabled="disabled">선택해주세요</option>
<c:forEach var="lprod" items="${lprod}">
<option value="${lprod.lprodGu}">${lprod.lprodNm}</option>
</c:forEach>
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<!-- text input -->
<div class="form-group">
<label for="prodName">상품 명</label> <input required type="text"
class="form-control" placeholder="상품명" name="prodName"
id="prodName">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="prodBuyer">거래처</label> <select required class="form-control"
id="prodBuyer" name="prodBuyer">
<option value="" selected="selected" disabled="disabled">상품 분류를 선택해주세요</option>
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<!-- textarea -->
<div class="form-group">
<label for="prodSale">상품 판매가</label> <input required type="number"
class="form-control" placeholder="판매가" name="prodSale"
id="prodSale">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label>업로드 파일</label>
<div class="custom-file">
<input required type="file" class="custom-file-input" name="uploadFile"
id="uploadFile" multiple="multiple"> <label class="custom-file-label" id="fileLabel"
for="uploadFile">파일을 선택해주세요</label>
</div>
</div>
<div id="pImg">
<!-- <img src="/resources/images/P1234.jpg" style="width: 100px; border:1px solid #ced4da;border-radius: .25rem;" /> -->
</div>
</div>
</div>
<!-- input states -->
<div class="form-group">
<label class="col-form-label" for="prodDetail">상품 상세 설명</label>
<div id="prodDetailTemp"></div>
<textarea hidden class="form-control" rows="3" id="prodDetail"
placeholder="상품 상세 설명" name="prodDetail" cols=""></textarea>
</div>
</div>
<!-- /.card-body -->
<div class="card-footer row" style="justify-content: space-between;">
<div>
<a href="/prod/list" class="btn btn-info">목록</a>
</div>
<div>
<button type="submit" class="btn btn-warning">등록</button>
</div>
<div>
<button type="reset" id="reset" class="btn btn-secondary">초기화</button>
</div>
</div>
</form>
</div>
<script>
// uploadUrl => 이미지 업로드 시 요청할 요청URI
// editor => CKEditor가 생성된 후 바로 그 객체
// window.editor : 그 객체를 이렇게 부르겠다 정의
ClassicEditor.create( document.querySelector('#prodDetailTemp'),{ckfinder:{uploadUrl:'/image/upload'}})
.then(editor=>{window.editor=editor;})
.catch(err=>{console.error(err.stack);});
document.getElementById('uploadFile').addEventListener('change', function(event) {
const files = event.target.files; // 업로드된 파일 목록
const imagePreviewContainer = document.getElementById('pImg');
imagePreviewContainer.innerHTML = ''; // 기존 미리보기 초기화
// 업로드된 파일을 미리보기로 표시
for (let i = 0; i < files.length; i++) {
const file = files[i];
const reader = new FileReader();
reader.onload = function(e) {
const imgContainer = document.createElement('div');
imgContainer.className = 'image-container';
imgContainer.style.position = 'relative';
imgContainer.style.display = 'inline-block';
imgContainer.style.margin = '5px';
// 이미지 생성
const img = document.createElement('img');
img.src = e.target.result; // FileReader로 읽은 이미지 URL
img.style.width = '100px';
img.style.border = '1px solid #ced4da';
img.style.borderRadius = '.25rem';
// 삭제 버튼 생성
const button = document.createElement('button');
button.type = 'button';
button.className = 'btn btn-tool';
button.style.position = 'absolute';
button.style.top = '5px';
button.style.right = '-1px';
button.style.background = 'rgba(255, 255, 255, 0.8)';
button.style.border = 'none';
button.style.borderRadius = '50%';
button.style.padding = '2px';
button.style.cursor = 'pointer';
button.innerHTML = '<i class="fas fa-times"></i>';
// 삭제 버튼 클릭 시 동작
button.onclick = function() {
// 이미지 컨테이너 삭제
imgContainer.remove();
// 업로드된 파일 목록에서 해당 파일 삭제
const fileList = Array.from(document.getElementById('uploadFile').files);
const newFileList = fileList.filter((_, index) => index !== i); // 현재 인덱스 제외
const dataTransfer = new DataTransfer(); // 새로운 파일 리스트 생성
newFileList.forEach(file => dataTransfer.items.add(file)); // 새로운 파일 리스트 추가
document.getElementById('uploadFile').files = dataTransfer.files; // 파일 입력 필드 업데이트
};
// 이미지 컨테이너에 이미지와 버튼 추가
imgContainer.appendChild(img);
imgContainer.appendChild(button);
imagePreviewContainer.appendChild(imgContainer);
};
reader.readAsDataURL(file); // 파일을 데이터 URL로 읽기
}
});
function removeImage(button) {
// Find the parent container of the button
const imageContainer = button.closest('.image-container');
// Remove the image container from the DOM
if (imageContainer) {
imageContainer.remove();
}
}
$(function(){
$(".ck-blurred").keydown(function(){
console.log("str : " + window.editor.getData());
$("#prodDetail").val(window.editor.getData());
});
$(".ck-blurred").on("focusout",function(){
$("#prodDetail").val(window.editor.getData());
});
$('#prodLgu').on('change',function(){
let lgu = $('#prodLgu').val();
// prodId 생성
$.ajax({
url : "/prod/createProdId",
data : JSON.stringify({"prodLgu" : lgu}),
contentType : 'application/json',
type : "post",
success : function(res){
$('#prodId').val(res);
}
})
// buyer select 설정
$.ajax({
url : "/prod/buyer",
data : JSON.stringify({"buyerLgu" : lgu}),
contentType : 'application/json',
type : "post",
success : function(res){
console.log(res);
let str="<option value='' selected disabled>선택해주세요</option>";
$.each(res, function(){
str += "<option value='"+this.buyerId+"'>"+this.buyerName+"</option>";
})
if(res.length==0){
str = "<option value='' selected disabled>해당하는 거래처가 없습니다</option>"
}
$('#prodBuyer').html(str);
}
})
})
// reset시 buyer select도 리셋
$('#reset').on('click',function(){
let str="<option value='' selected disabled>상품 분류를 선택해주세요</option>";
$('#prodBuyer').html(str);
})
})
</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 MultipartFile[] uploadFile;
private List<CartVO> cartVoList;
}
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";
}
}
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);
}
ProdServiceImpl.java
package kr.or.ddit.service.impl;
import java.io.File;
import java.util.ArrayList;
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 uploadFile = new File(this.uploadPath, 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/"+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;
}
}
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);
}
Mybatis
prod_SQL.xml
namespace변경 후 상품등록 관련 sql 추가
<?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="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>
</mapper>
'Spring' 카테고리의 다른 글
[Spring] 상품 추가에 상품 이미지 미리보기 (0) | 2024.08.08 |
---|---|
[Spring] CKEditor5 (0) | 2024.08.08 |
[Spring] sql delete한 데이터 불러오기 (0) | 2024.08.07 |
[Spring] Member와 사진 연결 (0) | 2024.08.06 |
[Spring] mapper interface (0) | 2024.08.06 |