본문 바로가기

안녕하세요!

프로그래밍 언어/JSP

JSP_22-11-22_상품 등록[2]

[ ProductDTO.java ]

package com.edu.product.dto;

import java.sql.Date;

import org.springframework.stereotype.Component;

import lombok.Data;

@Component
@Data
public class ProductDTO {

	private int 	product_id;			// 상품 아이디
	private String 	p_name;				// 상품 이름
	private String 	p_explanation;			// 상품 설명
	private int 	p_price;			// 상품 가격
	private int 	p_sell;					

	private Date 	p_enroll;			// 상품 등록일	
	
}

 

[ ProductController.java ]

package com.edu.product.controller;

import javax.inject.Inject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.edu.product.service.ProductService;

//-----------------------------------------------------------------------------------------------------------
// 상품 등록 화면 불러오기
//-----------------------------------------------------------------------------------------------------------
@Controller
@RequestMapping(value = "/product/*")
public class ProductController {

	private static final Logger logger = LoggerFactory.getLogger(ProductController.class);

	@Inject
	private	ProductService productService;
	
	//-----------------------------------------------------------------------------------------------------------
	// 상품 등록 화면 불러오기
	//-----------------------------------------------------------------------------------------------------------
	@RequestMapping(value = "/productEnrollForm", method = RequestMethod.GET)
	public String productEnrollForm() throws Exception {
		
		logger.info("ProductController 상품 등록 화면 불러오기.....");
		return "/product/productEnrollForm";
		
	}
	
}

 

[ ProductDAO.java ]

package com.edu.product.dao;

import com.edu.product.dto.ProductDTO;

public interface ProductDAO {

	public int productEnroll(ProductDTO productDTO);
	
	
	
}

 

[ ProductDAOImpl.java ]

package com.edu.product.dao;

import javax.inject.Inject;

import org.apache.ibatis.session.SqlSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.edu.product.dto.ProductDTO;

@Repository
public class ProductDAOImpl implements ProductDAO {

	private static final Logger logger = LoggerFactory.getLogger(ProductDAOImpl.class);

	
	@Inject
	private SqlSession sqlSession;
	
	private static String namespace = "com.edu.product";

	
	@Override
	public int productEnroll(ProductDTO productDTO) {

		logger.info("ProductDAOImpl 상품 등록 처리 ==> " + productDTO);

		
		return sqlSession.insert(namespace + ".insertProduct", productDTO);
	}

	
	
}

 

[ ProductService.java ]

package com.edu.product.service;

import com.edu.product.dto.ProductDTO;

public interface ProductService {

	public void productEnroll(ProductDTO productDTO) throws Exception;
	
	
	
	
}

 

[ ProductServiceImpl.java ]

package com.edu.product.service;

import javax.inject.Inject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.edu.product.dao.ProductDAO;
import com.edu.product.dto.ProductDTO;

@Service
public class ProductServiceImpl implements ProductService {

	private static final Logger logger = LoggerFactory.getLogger(ProductServiceImpl.class);

	@Inject
	private ProductDAO productDAO;
	
	@Override
	public void productEnroll(ProductDTO productDTO) throws Exception {

		logger.info("ProductServiceImpl 상품 등록 처리 ==> " + productDTO);

		
		productDAO.productEnroll(productDTO);
	}




	
}

 

728x90
반응형

loading