Tiny Bunny [Spring] 최종 팀 프로젝트 : 컨트롤러 Spring 이관 - 솜님의 블로그
솜님의 블로그
카테고리
작성일
2024. 11. 1. 02:17
작성자
겨울솜사탕

기존 JSP 프로젝트 → 최종 프로젝트로 가면서 Spring으로 이관을 하게 되었다.
 
스프링 프레임워크는 IoC와 AOP를 지원하는 경량의 프레임워크를 의미한다.
IoC란 제어의 역행이라고 하며, 제어권을 컨테이너에게 준다는 것을 의미한다.
(컨테이너가 객체를 new 해준다는 것!)
 
컨테이너는 xml(설정파일)이 있어야 동작을 하고,
이 xml에서는 <bean>을 통해 객체를 new 해줄 수 있다.
 
그러나 xml에 과도한 설정이 싫기 때문에 @어노테이션을 사용한다.
 
또 기존에는 액션 포워드를 반환해 주었는데,
Spring에서는 액션 포워드가 무겁다고 느끼기 때문에 이를 반환하지 않고
View Resolver를 사용하여 어디로 보내야 할지 판단해 주는 객체를 사용한다.
 
이러한 과정을 기존 프로젝트에 적용시켜 코드  수정이 되었다.
 
우리 프로젝트에서는 총 11개의 테이블이 있고,
나는 그중에서 상품 / 리뷰 / 위시리스트 / 게시판 / 댓글을 담당했다.
 
 

비동기

더보기
더보기

✨ 비동기 (Async)

 

 

package com.korebap.app.view.async;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.korebap.app.biz.board.BoardDTO;
import com.korebap.app.biz.board.BoardService;
import com.korebap.app.biz.goodLike.GoodLikeDTO;
import com.korebap.app.biz.goodLike.GoodLikeService;
import com.korebap.app.view.util.LoginCheck;


@RestController
public class BoardAsyncController {

	@Autowired
	private GoodLikeService goodLikeService;

	@Autowired
	private BoardService boardService;

	@Autowired
	private LoginCheck loginCheck; // 로그인 상태 확인 유틸리티 주입

	// 게시글 좋아요
	@RequestMapping(value="/boardLike.do", method=RequestMethod.POST)
	public @ResponseBody Map<String, Object> boardLike(@RequestBody GoodLikeDTO goodLikeDTO, BoardDTO boardDTO) {
		// 좋아요 비동기
		System.out.println("************************************************************[com.korebap.app.view.async boardLike (비동기) 시작]************************************************************");

		// json 타입으로 반환하기 위한 Map 객체 생성
		Map<String, Object> responseMap = new HashMap<>();

		// 현재 로그인된 사용자의 ID 확인
		String login_member_id = loginCheck.loginCheck();

		// 만약 로그인된 id가 없다면
		if (login_member_id.equals("")) {
			System.out.println("*****com.korebap.app.view.async boardLike 로그인 상태 아닌 경우*****");
			responseMap.put("message", "로그인 후 이용해 주세요."); // 안내 메시지
			responseMap.put("redirect", "login.do"); // 로그인 페이지 URL
			return responseMap;
		}

		int board_num = goodLikeDTO.getGoodLike_board_num(); // 글 번호

		// 데이터 로그
		System.out.println("*****com.korebap.app.view.async boardLike board_num ["+board_num+"]*****");
		System.out.println("*****com.korebap.app.view.async boardLike login_member_id ["+login_member_id+"]*****");


		// 저장된 아이디와 글 번호를 넣고 service에게 보내서 반환 (좋아요 여부 확인하기 위함)
		goodLikeDTO.setGoodLike_member_id(login_member_id);
		goodLikeDTO.setGoodLike_board_num(board_num);
		GoodLikeDTO newLikeDTO = goodLikeService.selectOne(goodLikeDTO);

		System.out.println("*****com.korebap.app.view.async boardLike newLikeDTO ["+newLikeDTO+"]*****");


		boolean flag = true;

		// 좋아요 한 내역이 없다면 (객체가 null이라면)
		if(newLikeDTO == null) {
			System.out.println("*****com.korebap.app.view.async boardLike 기존에 좋아요 내역 없음-insert*****");

			// 기존 id와 board_num 넣은 객체를 보내서 좋아요 insert
			goodLikeService.insert(goodLikeDTO);
		}
		else {
			System.out.println("*****com.korebap.app.view.async boardLike 기존에 좋아요 내역 있음-delete*****");

			// 기존에 좋아요 한 데이터 객체를 보내서 delete
			goodLikeService.delete(newLikeDTO);
			flag = false;
		}

		// 좋아요 수를 비동기로 보여줘야 하기 때문에 DTO 객체에 글 번호를 담아 개수 확인
		boardDTO.setBoard_num(board_num);
		boardDTO.setBoard_condition("BOARD_SELECT_ONE");
		boardDTO = boardService.selectOne(boardDTO); 

		// ajax 요청 응답
		responseMap.put("flag",flag); // true / false
		responseMap.put("likeCnt",boardDTO.getBoard_like_cnt()); // 좋아요 수

		System.out.println("************************************************************[com.korebap.app.view.async boardLike (비동기) 종료]************************************************************");

		return responseMap;


	} // 좋아요 메서드 종료




	// 게시판 무한스크롤 비동기 구현하는 컨트롤러
	@RequestMapping(value="/boardListScroll.do", method=RequestMethod.GET)
	public @ResponseBody Map<String, Object> boardListScroll(BoardDTO boardDTO, @RequestParam(value="currentPage") int current_page) {

		System.out.println("************************************************************[com.korebap.app.view.async boardListScroll (비동기) 시작]************************************************************");


		// [게시글 전체 출력]
		// 검색어와 정렬 기준을 변수에 넣어준다.
		String searchKeyword = boardDTO.getBoard_searchKeyword(); // 검색어
		String search_criteria = boardDTO.getBoard_search_criteria(); // 정렬 기준

		// 데이터 로그
		System.out.println("*****com.korebap.app.view.async boardListScroll 로그 searchKeyword : [" + searchKeyword +"]*****");
		System.out.println("*****com.korebap.app.view.async boardListScroll 로그 board_search_criteria : [" + search_criteria +"]*****");
		System.out.println("*****com.korebap.app.view.async boardListScroll 로그 current_page : [" + current_page +"]*****");


		// 현재 페이지 번호를 M에게 보내 데이터를 반환받는다
		boardDTO.setBoard_page_num(current_page);
		boardDTO.setBoard_condition("BOARD_ALL"); // 전체출력 컨디션

		List<BoardDTO> boardList = boardService.selectAll(boardDTO);

		System.out.println("*****com.korebap.app.view.async boardListScroll 로그 boardList ["+boardList+"]*****");



		// [게시판 페이지 전체 개수]
		boardDTO.setBoard_condition("BOARD_PAGE_COUNT");
		boardDTO = boardService.selectOne(boardDTO);
		// int 타입 변수에 받아온 값을 넣어준다.
		int board_total_page = boardDTO.getBoard_total_page();

		System.out.println("*****com.korebap.app.view.async boardListScroll 로그 board_page_count ["+board_total_page+"]*****");


		// 마지막 페이지 요청 시 처리
		// 현재 페이지 > 전체 페이지 수
		if (current_page > board_total_page) {
			System.out.println("*****com.korebap.app.view.async boardListScroll 마지막 페이지 요청*****");
			// 전달할 데이터가 없으므로 null 반환
			return null;
		}

		// 결과를 Map에 담아 반환
		Map<String, Object> responseMap = new HashMap<>();
		responseMap.put("boardList", boardList);
		responseMap.put("totalPage", board_total_page);

		System.out.println("*****com.korebap.app.view.async boardListScroll 로그 responseMap ["+responseMap+"]*****");

		System.out.println("************************************************************[com.korebap.app.view.async boardListScroll (비동기) 종료]************************************************************");
		return responseMap;

	}


}

 

package com.korebap.app.view.async;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.korebap.app.biz.wishlist.WishlistDTO;
import com.korebap.app.biz.wishlist.WishlistService;

// wishList 관련 비동기 class
@RestController
public class DeleteWishListController {

	@Autowired
	private WishlistService wishlistService;

	@RequestMapping(value="/deleteWishList.do", method=RequestMethod.POST)
	public @ResponseBody String deleteWishList(WishlistDTO wishlistDTO) {
		// [ 위시리스트 삭제 ]

		System.out.println("************************************************************[com.korebap.app.view.async deleteWishList (비동기) 시작]************************************************************");


		// V에게 삭제할 위시리스트 번호를 받아온다.
		int wishlist_num = wishlistDTO.getWishlist_num();

		// 데이터 로그
		System.out.println("*****com.korebap.app.view.async WishList deleteWishList wishlist_num["+wishlist_num+"]*****");


		// DTO 객체에 위시리스트 번호를 담아준다.
		wishlistDTO.setWishlist_num(wishlist_num);
		// M에게 DTO객체를 전달해주고, boolean 타입으로 반환받는다.
		boolean flag = wishlistService.delete(wishlistDTO);

		// 응답을 반환하기 위한 변수 설정
		// default 성공으로 보고 반환
		String result = "true";

		if(!flag) { // 만약 false 반환받는다면 
			// 실패 응답 반환
			System.out.println("*****com.korebap.app.view.async WishList deleteWishList 비동기 실패 반환*****");
			result = "false";
		}


		System.out.println("*****com.korebap.app.view.async WishList deleteWishList result ["+result+"]*****");

		System.out.println("************************************************************[com.korebap.app.view.async deleteWishList (비동기) 종료]************************************************************");
		return result;

	}

}

 

 

package com.korebap.app.view.async;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.korebap.app.biz.product.ProductDTO;
import com.korebap.app.biz.product.ProductService;


@RestController
public class ProductAsyncController {

	@Autowired
	private ProductService productService;

	@RequestMapping(value="/productList.do", method=RequestMethod.GET)
	public @ResponseBody Map<String, Object> productPage(ProductDTO productDTO,
			@RequestParam(value="currentPage", required = false, defaultValue = "1") int current_page) {

		System.out.println("************************************************************[com.korebap.app.view.async productPage (비동기) 시작]************************************************************");

		// [ 상품 페이지네이션]
		// 데이터로그
		System.out.println("*****com.korebap.app.view.async productPage 비동기 currentPage [" + current_page + "]*****");
		System.out.println("*****com.korebap.app.view.async productPage 비동기 product_searchKeyword [" + productDTO.getProduct_searchKeyword() + "]*****");
		System.out.println("*****com.korebap.app.view.async productPage 비동기 product_location [" + productDTO.getProduct_location() + "]*****");
		System.out.println("*****com.korebap.app.view.async productPage 비동기 product_category [" + productDTO.getProduct_category() + "]*****");
		System.out.println("*****com.korebap.app.view.async productPage 비동기 product_search_criteria [" + productDTO.getProduct_search_criteria() + "]*****");
		System.out.println("*****com.korebap.app.view.async productPage 비동기 Product_page_num [" + productDTO.getProduct_page_num() + "]*****");

		
		// 카테고리와 위치에 대한 기본값 설정
		if (productDTO.getProduct_category() == null || productDTO.getProduct_category().isEmpty()) {
			productDTO.setProduct_category(null); // 필터 적용하지 않음
		}

		if (productDTO.getProduct_location() == null || productDTO.getProduct_location().isEmpty()) {
			productDTO.setProduct_location(null); // 필터 적용하지 않음
		}


		//M에게 데이터를 보내주고, 결과를 ArrayList로 반환받는다. 
		productDTO.setProduct_page_num(current_page);
		List<ProductDTO> productList = productService.selectAll(productDTO);

		System.out.println("*****com.korebap.app.view.async productPage 비동기 productList [" + productList + "]*****");


		
		// [게시판 페이지 전체 개수]
		productDTO.setProduct_condition("PRODUCT_PAGE_COUNT");
		productDTO = productService.selectOne(productDTO);

		// int 타입 변수에 받아온 값을 넣어준다.
		int product_total_page = productDTO.getProduct_total_page();

		System.out.println("*****com.korebap.app.view.async productPage 비동기 product_total_page [" + product_total_page + "]*****");

		// 현재 페이지 > 전체 페이지
		if (current_page > product_total_page) {
			System.out.println("*****com.korebap.app.view.async productPage 비동기 : 마지막 페이지 요청, 더 이상 데이터 없음");
			return null;
		}


		// 결과를 Map에 담아 반환
		Map<String, Object> responseMap = new HashMap<>();
		responseMap.put("productList", productList);
		responseMap.put("product_page_count", product_total_page);
		responseMap.put("currentPage", current_page);


		System.out.println("*****com.korebap.app.view.async productPage 비동기 responseMap" +responseMap+ "]");

		System.out.println("************************************************************[com.korebap.app.view.async productPage (비동기) 종료]************************************************************");

		return responseMap; 
	}

}

 

 

package com.korebap.app.view.async;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.korebap.app.biz.reply.ReplyDTO;
import com.korebap.app.biz.reply.ReplyService;

@RestController
public class ReplyAsyncController {

    @Autowired
    private ReplyService replyService; // ReplyService를 의존성 주입

    @RequestMapping(value = "/updateReply.do",method = RequestMethod.POST)
    public @ResponseBody boolean updateReply(@RequestBody ReplyDTO replyDTO) {
		System.out.println("************************************************************[com.korebap.app.view.async updateReply (비동기) 시작]************************************************************");

        // 데이터 로그
        System.out.println("*****com.korebap.app.view.async updateReply reply_num : [" + replyDTO.getReply_num() +"]*****");
        System.out.println("*****com.korebap.app.view.async updateReply reply_content : [" + replyDTO.getReply_content() +"]*****");

        // 데이터베이스 업데이트
        boolean flag = replyService.update(replyDTO);

        // 응답 반환
        if (flag) { // 성공
            System.out.println("*****com.korebap.app.view.async updateReply 변경 성공*****");
        }
        else { // 실패
            System.out.println("*****com.korebap.app.view.async updateReply 변경 실패*****");
        }
        
		System.out.println("************************************************************[com.korebap.app.view.async updateReply (비동기) 종료]************************************************************");

        return flag;
    }
}

 
 

Board

더보기
더보기

✨ Board (게시판)

package com.korebap.app.view.board;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.korebap.app.biz.board.BoardDTO;
import com.korebap.app.biz.board.BoardService;
import com.korebap.app.biz.goodLike.GoodLikeDTO;
import com.korebap.app.biz.goodLike.GoodLikeService;
import com.korebap.app.biz.imagefile.ImageFileDTO;
import com.korebap.app.biz.imagefile.ImageFileService;
import com.korebap.app.biz.reply.ReplyDTO;
import com.korebap.app.biz.reply.ReplyService;

import jakarta.servlet.http.HttpSession;

@Controller
public class BoardDetailController {
	@Autowired
	private BoardService boardService;
	
	@Autowired
	private ImageFileService fileService;
	
	@Autowired
	private ReplyService replyService;
	
	@Autowired
	private GoodLikeService goodLikeService;
	
	@RequestMapping(value="/boardDetail.do", method=RequestMethod.GET)
	public String boardDetail(HttpSession session,BoardDTO boardDTO,ImageFileDTO imagefileDTO, ReplyDTO replyDTO,
			GoodLikeDTO goodLikeDTO, Model model) {
		
		System.out.println("************************************************************[com.korebap.app.view.board boardDetail 시작]************************************************************");
		
		// 아이디 가지고 온다 (좋아요 여부 확인 필요)
		String member_id = (String)session.getAttribute("member_id");
		int board_num = boardDTO.getBoard_num();
		// 데이터 로그
		System.out.println("*****com.korebap.app.view.board boardDetail member_id 확인 : ["+member_id+"]*****");
		System.out.println("*****com.korebap.app.view.board boardDetail board_num 확인 : ["+board_num+"]*****");
		
		
		
		// 글 번호로 [게시글] 찾기
		boardDTO.setBoard_condition("BOARD_SELECT_ONE");
		boardDTO = boardService.selectOne(boardDTO);
		

		// 게시글 번호를 DTO에 넣어서 [전체 파일]을 불러온다.
		imagefileDTO.setFile_board_num(board_num);
		imagefileDTO.setFile_condition("BOARD_FILE_SELECTALL");
		List<ImageFileDTO> fileList = fileService.selectAll(imagefileDTO);
		

		// 게시글 번호를 DTO에 넣어서 [전체 댓글]을 불러온다.
		replyDTO.setReply_board_num(board_num);
		List<ReplyDTO> replyList=replyService.selectAll(replyDTO);
		
		
		// [좋아요 여부]를 확인하여 여부에 따라 색상을 표시하도록 view에게 전달 필요함
		goodLikeDTO.setGoodLike_board_num(board_num);
		goodLikeDTO.setGoodLike_member_id(member_id);
		goodLikeDTO = goodLikeService.selectOne(goodLikeDTO);
		
		// view에게 좋아요 여부를 true/false로 반환한다
		String flag = "true"; // 좋아요 한 상태
		if(goodLikeDTO == null) {
			// 좋아요 하지 않았다면 false로 변경
			System.out.println("*****com.korebap.app.view.board boardDetail goodLikeDTO 좋아요 하지 않은 상태*****");

			flag = "false";
		}
		
		
		// 로그
		System.out.println("*****com.korebap.app.view.board boardDetail boardDTO 확인 : ["+boardDTO+"]*****");
		System.out.println("*****com.korebap.app.view.board boardDetail fileList 확인 : ["+fileList+"]*****");
		System.out.println("*****com.korebap.app.view.board boardDetail replyList 확인 : ["+replyList+"]*****");
		System.out.println("*****com.korebap.app.view.board boardDetail flag(좋아요 여부) 확인 : ["+flag+"]*****");

		
		model.addAttribute("board", boardDTO);
		model.addAttribute("fileList", fileList);
		model.addAttribute("replyList", replyList);
		model.addAttribute("like_member", flag);
		
		System.out.println("************************************************************[com.korebap.app.view.board boardDetail 종료]************************************************************");

		// 글 상세페이지로 이동시킴
		return "boardDetails";
	}

}

 

 

 

package com.korebap.app.view.board;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.korebap.app.biz.board.BoardDTO;
import com.korebap.app.biz.board.BoardService;
import com.korebap.app.view.util.LoginCheck;

import jakarta.servlet.http.HttpSession;


@Controller
public class DeleteBoardController {

	@Autowired
	private BoardService boardService;

	@Autowired
	private LoginCheck loginCheck; // 로그인 상태 확인 유틸리티 주입


	@RequestMapping(value="/deleteBoard.do", method=RequestMethod.POST)
	public String deleteBoard(BoardDTO boardDTO, Model model,RedirectAttributes redirectAttributes) {
		// [ 게시글 삭제 ]

		System.out.println("************************************************************[com.korebap.app.view.board deleteBoard 시작]************************************************************");

		// 경로를 담을 변수
		String viewName = "info";

		// 상세페이지로 이동시키기 위해 변수 선언
		int board_num = boardDTO.getBoard_num();

		// 현재 로그인된 사용자의 ID 확인
		String member_id = loginCheck.loginCheck();

		// 데이터 로그
		System.out.println("*****com.korebap.app.view.board deleteBoard member_id 확인 : ["+member_id+"]*****");
		System.out.println("*****com.korebap.app.view.board deleteBoard board_num 확인 : ["+board_num+"]*****");


		if(member_id.equals("")) { // 만약 로그인 상태가 아니라면 
			System.out.println("*****com.korebap.app.view.board deleteBoard 로그인 세션 없음*****");

			// 로그인 안내 후 login 페이지로 이동시킨다
			model.addAttribute("msg", "로그인이 필요한 서비스입니다.");
			model.addAttribute("path", "loginPage.do");

		}
		else { // 로그인 상태일때
			System.out.println("*****com.korebap.app.view.board deleteBoard 로그인 세션 있음*****");

			// service를 통하여 게시글 삭제 요청을 한다
			boolean flag = boardService.delete(boardDTO);

			if(flag) { // 삭제 성공시
				System.out.println("*****com.korebap.app.view.board deleteBoard 게시글 삭제 성공*****");

				// 글 목록 페이지로 이동
				viewName ="redirect:boardListPage.do";
			}
			else { // 삭제 실패시
				System.out.println("*****com.korebap.app.view.board deleteBoard 게시글 삭제 실패*****");

				model.addAttribute("msg", "게시글 삭제에 실패했습니다. 다시 시도해 주세요.");
				model.addAttribute("path", "boardDetail.do?boardNum="+board_num);
			}

		}

		System.out.println("*****com.korebap.app.view.board deleteBoard viewName ["+viewName+"]*****");

		System.out.println("************************************************************[com.korebap.app.view.board deleteBoard 종료]************************************************************");
		return viewName;
	}

}

 

 

package com.korebap.app.view.board;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.korebap.app.biz.board.BoardDTO;
import com.korebap.app.biz.board.BoardService;
import com.korebap.app.view.util.LoginCheck;

import jakarta.servlet.http.HttpSession;



@Controller
public class UpdateBoardController {
	
	@Autowired
	private BoardService boardService;
	
	@Autowired
	private LoginCheck loginCheck;
	
	
	@RequestMapping(value="/updateBoard.do", method=RequestMethod.GET)
	public String updateBoardPage(BoardDTO boardDTO, Model model) {
		// [ 게시글 수정]
		System.out.println("************************************************************[com.korebap.app.view.page updateBoardPage 시작]************************************************************");

		System.out.println("*****com.korebap.app.view.page updateBoardPage 시작*****");

		// 경로를 담을 변수
		String viewName;

		// 상세페이지로 이동시키기 위해 변수 선언
		int board_num = boardDTO.getBoard_num();

		// 로그인 체크
		String login_member_id = loginCheck.loginCheck();


		// 데이터 로그
		System.out.println("*****com.korebap.app.view.page updateBoardPage member_id 확인 : ["+login_member_id+"]*****");
		System.out.println("*****com.korebap.app.view.page updateBoardPage board_num 확인 : ["+board_num+"]*****");


		if(login_member_id.equals("")) { // 만약 로그인 상태가 아니라면 
			System.out.println("*****com.korebap.app.view.page updateBoardPage 로그인 세션 없음*****");

			// 로그인 안내 후 login 페이지로 이동시킨다
			model.addAttribute("msg", "로그인이 필요한 서비스입니다.");
			model.addAttribute("path", "loginPage.do");

			// 데이터를 보낼 경로
			viewName = "info";
		}
		else {
			
			System.out.println("*****com.korebap.app.view.page updateBoardPage 로그인 세션 있음*****");
			
			boardDTO = boardService.selectOne(boardDTO);
			
			model.addAttribute("board", boardDTO);
			
			viewName ="updateBoard";
			
		}

		System.out.println("=====com.korebap.app.view.page updateBoardPage viewName ["+viewName+"]");

		System.out.println("************************************************************[com.korebap.app.view.page updateBoardPage 종료]************************************************************");

		return viewName;
	}
	
	

	@RequestMapping(value="/updateBoard.do", method=RequestMethod.POST)
	public String updateBoard(BoardDTO boardDTO, Model model, RedirectAttributes redirectAttributes) {
		// [ 게시글 수정 ]

		System.out.println("************************************************************[com.korebap.app.view.board updateBoard 시작]************************************************************");


		// 경로를 담을 변수
		String viewName = "info";

		// 상세페이지로 이동시키기 위해 변수 선언
		int board_num = boardDTO.getBoard_num();

		// 로그인 체크 
		String member_id = loginCheck.loginCheck();

		// 데이터 로그
		System.out.println("*****com.korebap.app.view.board updateBoard member_id 확인 : ["+member_id+"]*****");
		System.out.println("*****com.korebap.app.view.board updateBoard board_num 확인 : ["+board_num+"]*****");
		System.out.println("*****com.korebap.app.view.board updateBoard boardDTO 확인 : ["+boardDTO+"]*****");


		if(member_id.equals("")) { // 만약 로그인 상태가 아니라면 
			System.out.println("*****com.korebap.app.view.board updateBoard 로그인 세션 없음*****");

			// 로그인 안내 후 login 페이지로 이동시킨다
			model.addAttribute("msg", "로그인이 필요한 서비스입니다.");
			model.addAttribute("path", "login.do");
		}
		else { // 로그인 상태라면
			
			System.out.println("*****com.korebap.app.view.board updateBoard 로그인 세션 있음*****");

			// Service에게 DTO 객체를 보내서 update 시킨다
			boolean flag = boardService.update(boardDTO);
			
			if(flag) { // 변경 성공했다면
				System.out.println("*****com.korebap.app.view.board updateBoard 게시글 변경 성공*****");

				// 게시글 상세 페이지로 이동
				// 리다이렉트시 쿼리 매개변수를 자동으로 URL에 포함
				// 쿼리 매개변수 == URL에서 ? 기호 뒤에 위치하는 key-value 쌍
				redirectAttributes.addAttribute("board_num", board_num);

				viewName = "redirect:boardDetail.do";
				
			}
			else { // 변경 실패했다면 
				System.out.println("*****com.korebap.app.view.board updateBoard 게시글 변경 실패*****");
				// 안내 + 게시글 상세 페이지로 이동
				
				model.addAttribute("msg", "게시글 수정에 실패했습니다. 다시 시도해주세요.");
				model.addAttribute("path", "boardDetail.do?board_num="+board_num);
				
				viewName = "info";
			}
			
		}

		System.out.println("*****com.korebap.app.view.board updateBoard viewName ["+viewName+"]*****");
		System.out.println("************************************************************[com.korebap.app.view.board updateBoard 종료]************************************************************");
		return viewName;
	}

}

 

 

 

package com.korebap.app.view.board;


import java.io.IOException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.korebap.app.biz.board.BoardDTO;
import com.korebap.app.biz.board.BoardInsertTransaction;
import com.korebap.app.biz.imagefile.ImageFileDTO;
import com.korebap.app.view.util.LoginCheck;

import jakarta.servlet.http.HttpSession;

@Controller
public class WriteBoardController {

	@Autowired
	private BoardInsertTransaction boardInsertTransaction; // 트랜잭션

	@Autowired
	private LoginCheck loginCheck;

	// 글 작성 페이지 이동
	@RequestMapping(value="/writeBoard.do", method=RequestMethod.GET)
	public String writeBoardPage(Model model) {
		// [ 게시글 작성 페이지 이동]
		System.out.println("************************************************************[com.korebap.app.view.board writeBoardPage 시작]************************************************************");


		// 경로 저장해줄 변수
		String viewName;

		// 로그인 체크
		String member_id = loginCheck.loginCheck();

		System.out.println("*****com.korebap.app.view.page writeBoardPage member_id ["+member_id+"]*****");


		if(member_id.equals("")) { // 만약 로그인 상태가 아니라면 
			System.out.println("*****com.korebap.app.view.page writeBoardPage 로그인 세션 없음*****");

			// 로그인 안내 후 login 페이지로 이동시킨다
			model.addAttribute("msg", "로그인이 필요한 서비스입니다.");
			model.addAttribute("path", "login.do");

			// 데이터를 보낼 경로
			viewName = "info";
		}
		else { //  로그인 상태라면
			System.out.println("*****com.korebap.app.view.page writeBoardPage 로그인 세션 있음*****");

			viewName = "redirect:writeBoard.jsp";


		}

		System.out.println("*****com.korebap.app.view.page writeBoardPage viewName ["+viewName+"]*****");
		System.out.println("************************************************************[com.korebap.app.view.board writeBoardPage 종료]************************************************************");


		return viewName;
	}



	@RequestMapping(value="/writeBoard.do", method=RequestMethod.POST)
	public String writeBoard(HttpSession session, BoardDTO boardDTO, ImageFileDTO imageFileDTO, Model model,
			RedirectAttributes redirectAttributes, @RequestPart MultipartFile files) throws IllegalStateException, IOException  {

		// [ 게시글 작성 ]
		System.out.println("************************************************************[com.korebap.app.view.board writeBoard 시작]************************************************************");

		// 경로를 담을 변수
		// info로 보내는 경우가 많아서 info로 초기화
		String viewName = "info";

		// 로그인 체크
		String member_id = loginCheck.loginCheck();


		// 데이터 로그
		System.out.println("*****com.korebap.app.view.board writeBoard member_id 확인 : ["+member_id+"]*****");
		System.out.println("*****com.korebap.app.view.board writeBoard boardDTO 확인 : ["+boardDTO+"]*****");


		if(member_id.equals("")) { // 만약 로그인 상태가 아니라면 
			System.out.println("*****com.korebap.app.view.board writeBoard 로그인 세션 없음*****");

			// 로그인 안내 후 login 페이지로 이동시킨다
			model.addAttribute("msg", "로그인이 필요한 서비스입니다.");
			model.addAttribute("path", "login.do");

		}
		else {
			System.out.println("*****com.korebap.app.view.board writeBoard 로그인 세션 있음*****");
			
			// 로그인 정보를 가져와 DTO의 member_id에 담아준다. (M에게 전달 필요)
			boardDTO.setBoard_writer_id(member_id);

			try { // 트랜잭션 RuntimeException 발생 후 페이지 이동 시키기 위해 try-catch로 묶는다

				// 트랜잭션 요청
				boolean flag = boardInsertTransaction.insertBoardAndImg(boardDTO,imageFileDTO, files);

				// 상세페이지로 이동시키기 위해 변수 선언
				System.out.println("*****com.korebap.app.view.board writeBoard getBoard_num ["+boardDTO.getBoard_num()+"]*****");

				// 글/이미지 입력 성공시
				if(flag) {
					// 게시글 상세 페이지로 이동
					// 리다이렉트시 쿼리 매개변수를 자동으로 URL에 포함
					// 쿼리 매개변수 == URL에서 ? 기호 뒤에 위치하는 key-value 쌍
					redirectAttributes.addAttribute("board_num", boardDTO.getBoard_num());

					viewName = "redirect:boardDetail.do";
				}
				else { // 글 작성 실패
					System.out.println("*****com.korebap.app.view.board writeBoard 게시글 작성 실패*****");
					model.addAttribute("msg", "글 작성에 실패했습니다. 다시 시도해주세요.");
					model.addAttribute("path", "writeBoard.do");
				}
			} catch (RuntimeException e) {
				// 트랜잭션 중 예외 발생
				System.out.println("*****com.korebap.app.view.board writeBoard 트랜잭션 예외 발생: [" + e.getMessage()+"]");
				model.addAttribute("msg", "오류가 발생했습니다. 다시 시도해주세요.");
				model.addAttribute("path", "writeBoard.do");
			}

		}// else 끝 (로그인상태)

		
		System.out.println("*****com.korebap.app.view.board writeBoard viewName ["+viewName+"]*****");

		
		System.out.println("************************************************************[com.korebap.app.view.board writeBoard 종료]************************************************************");


		return viewName;
	}
}

 

 

package com.korebap.app.view.page;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.korebap.app.biz.board.BoardDTO;
import com.korebap.app.biz.board.BoardService;

import jakarta.servlet.http.HttpSession;

@Controller
public class BoardListPageAction {

	@Autowired
	private BoardService boardService;

	// 글 목록보기
	@RequestMapping(value="/boardListPage.do")
	public String boardListPage(BoardDTO boardDTO, Model model,@RequestParam(value="currentPage", defaultValue="1") int board_page_num) {
		// 인자로 받는 cruuentPage는 defaultValue를 설정하여 값이 없는 경우 1로 설정한다.
		// *초기 페이지이므로 null로 들어올 수 있음
		// [ 게시판 목록 페이지]
		
		System.out.println("************************************************************[com.korebap.app.view.page boardListPage 시작]************************************************************");

		
		String searchCriteria = boardDTO.getBoard_search_criteria(); // 검색어
		String searchKeyword = boardDTO.getBoard_searchKeyword(); // 키워드

		// 데이터 로그
		System.out.println("*****com.korebap.app.view.page boardListPage productDTO [" + boardDTO + "]*****");
		System.out.println("*****com.korebap.app.view.page boardListPage product_page_num [" + board_page_num + "]*****");
		System.out.println("*****com.korebap.app.view.page boardListPage searchCriteria [" + searchCriteria + "]*****");
		System.out.println("*****com.korebap.app.view.page boardListPage searchKeyword [" + searchKeyword + "]*****");


		
		// 사용자가 선택한 페이지번호 처리 (초기 1)
		boardDTO.setBoard_page_num(board_page_num);
		boardDTO.setBoard_condition("BOARD_ALL");

		//M에게 데이터를 보내주고, 결과를 ArrayList로 반환받는다. (게시판 전체 글)
		List<BoardDTO> boardList = boardService.selectAll(boardDTO);

		
		// [게시판 페이지 전체 개수]
		boardDTO.setBoard_condition("BOARD_PAGE_COUNT");
		boardDTO = boardService.selectOne(boardDTO);
		// int 타입 변수에 받아온 값을 넣어준다.
		int board_total_page = boardDTO.getBoard_total_page();


		// 전체 페이지 수가 1 미만이라면
		if (board_total_page < 1) {
			board_total_page = 1; // 최소 페이지 수를 1로 설정
		}

		// 데이터로그
		System.out.println("*****com.korebap.app.view.page boardListPage boardList ["+boardList+"]*****");
		System.out.println("*****com.korebap.app.view.page boardListPage board_total_page ["+board_total_page+"]*****");

		// view에게 전달하기 위해 model 객체에 저장
		model.addAttribute("boardList", boardList); // 게시판 list
		model.addAttribute("totalPage", board_total_page); // 전체 페이지 개수
		model.addAttribute("currentPage", board_page_num); // 현재 페이지 번호
		model.addAttribute("search_criteria",searchCriteria); // 검색 정렬 기준 (정렬 기준 유지시키기 위함)
		
		System.out.println("************************************************************[com.korebap.app.view.page boardListPage 종료]************************************************************");

		return "boardList";

	}

}

 
 

Product

더보기
더보기

✨ Product (상품)

 

package com.korebap.app.view.page;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.korebap.app.biz.product.ProductDTO;
import com.korebap.app.biz.product.ProductService;

@Controller
public class ProductListPageAction {

	@Autowired
	private ProductService productService;

	@RequestMapping(value="/productListPage.do", method=RequestMethod.GET)
	public String productListPage(ProductDTO productDTO, Model model, @RequestParam(value="currentPage", defaultValue="1") int product_page_num) {
		// 인자로 받는 cruuentPage는 defaultValue를 설정하여 값이 없는 경우 1로 설정한다.
		// *초기 페이지이므로 null로 들어올 수 있음

		// [ 상품 목록 페이지 ]
		System.out.println("************************************************************[com.korebap.app.view.page productListPage 시작]************************************************************");


		// 데이터 로그
		System.out.println("*****com.korebap.app.view.page productListPage productDTO ["+productDTO+"]*****");
		System.out.println("*****com.korebap.app.view.page productListPage product_page_num ["+product_page_num+"]*****");

		// V에서 받아온 파라미터
		String product_searchKeyword = productDTO.getProduct_searchKeyword(); // 검색어
		String product_location = productDTO.getProduct_location(); // 상품 장소 (바다,민물)
		String product_category = productDTO.getProduct_category(); // 상품 유형 (낚시배, 낚시터, 바다, 민물)
		String product_search_criteria = productDTO.getProduct_search_criteria(); // 최신, 좋아요, 찜, 예약 많은 순 >> 정렬기준

		// 데이터
		System.out.println("*****com.korebap.app.view.page productListPage product_searchKeyword ["+product_searchKeyword+"]*****");
		System.out.println("*****com.korebap.app.view.page productListPage product_location ["+product_location+"]*****");
		System.out.println("*****com.korebap.app.view.page productListPage product_category ["+product_category+"]*****");
		System.out.println("*****com.korebap.app.view.page productListPage product_search_criteria ["+product_search_criteria+"]*****");


		// 사용자가 선택한 페이지번호 처리
		productDTO.setProduct_page_num(product_page_num);
		// M에게 데이터를 보내주고 결과를 받음
		List<ProductDTO> productList = productService.selectAll(productDTO);

		System.out.println("*****com.korebap.app.view.page productListPage productList ["+productList+"]*****");



		// [전체 페이지 개수 받아오기]
		productDTO.setProduct_condition("PRODUCT_PAGE_COUNT");
		productDTO = productService.selectOne(productDTO);

		// int 타입 변수에 받아온 값을 넣어준다.
		int product_total_page = productDTO.getProduct_total_page();
		
		System.out.println("*****com.korebap.app.view.page productListPage product_total_page ["+product_total_page+"]*****");

		// 전체 페이지 수가 1보다 작다면
		if (product_total_page < 1) {
			product_total_page = 1; // 최소 페이지 수를 1로 설정
		}



		// 모델에 데이터 추가
		model.addAttribute("productList", productList); // 상품 목록
		model.addAttribute("product_location", product_location); // 위치 필터
		model.addAttribute("product_category", product_category); // 카테고리 필터
		model.addAttribute("searchOption", product_search_criteria); // 검색 기준
		model.addAttribute("product_page_count", product_total_page); // 페이지 수
		model.addAttribute("currentPage", product_page_num); // 현재 페이지

		System.out.println("************************************************************[com.korebap.app.view.page productListPage 종료]************************************************************");

		return "productList";
	}

}

 

 

package com.korebap.app.view.product;



import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.korebap.app.biz.imagefile.ImageFileDTO;
import com.korebap.app.biz.imagefile.ImageFileService;
import com.korebap.app.biz.product.ProductDTO;
import com.korebap.app.biz.product.ProductService;
import com.korebap.app.biz.review.ReviewDTO;
import com.korebap.app.biz.review.ReviewService;
import com.korebap.app.biz.wishlist.WishlistDTO;


@Controller
public class ProductDetailAction {
	
	@Autowired
	private ProductService productService;
	
	@Autowired
	private ReviewService reviewService;
	
	@Autowired
	private ImageFileService fileService;

	@RequestMapping(value="/productDetail.do", method=RequestMethod.GET)
	public String productDetail(Model model,ProductDTO productDTO, 
			ReviewDTO reviewDTO,ImageFileDTO fileDTO, WishlistDTO wishlistDTO) {

		// [ 상품 상세보기 ]
		System.out.println("************************************************************[com.korebap.app.view.product productDetail 시작]************************************************************");

		// 경로를 담을 변수 설정
		String viewName;
		
		// 상품 번호
		int product_num = productDTO.getProduct_num();
		
		// 데이터 로그
		System.out.println("*****com.korebap.app.view.product product_num ["+product_num+"]*****");

		
		// [상품 리스트] 반환
		productDTO.setProduct_condition("PRODUCT_BY_INFO");
		productDTO = productService.selectOne(productDTO);
		
		// [파일 리스트] 반환
		fileDTO.setFile_product_num(product_num);
		fileDTO.setFile_condition("PRODUCT_FILE_SELECTALL");
		List<ImageFileDTO> fileList = fileService.selectAll(fileDTO);

		// [리뷰 리스트] 반환
		reviewDTO.setReview_product_num(product_num);
		reviewDTO.setReview_condition("REVIEW_ALL");
		System.out.println("reviewDTO 확인 : "+reviewDTO+"]");
		List<ReviewDTO> reviewList = reviewService.selectAll(reviewDTO);

		
		// 만약 productDTO 객체가 있다면
		if(productDTO != null) {
			System.out.println("*****com.korebap.app.view.product productDetail 상품 상세 있음 *****");

			model.addAttribute("product", productDTO);
			model.addAttribute("fileList", fileList);
			model.addAttribute("reviewList", reviewList);
			
			viewName = "productDetail";
		}
		else {
			System.out.println("*****com.korebap.app.view.product productDetail 상품 상세 없음 *****");
			
			model.addAttribute("msg", "상품을 찾을 수 없습니다. 다시 시도해 주세요.");
			model.addAttribute("path", "productList.do");
			
			viewName = "info";
			
		}
		System.out.println("*****com.korebap.app.view.product productDetail viewName ["+ viewName +"]*****");
		
		System.out.println("************************************************************[com.korebap.app.view.product productDetail 종료]************************************************************");

		return viewName;
	}

}

 

 
 

Reply

더보기
더보기

✨ Reply (댓글)

 

package com.korebap.app.view.reply;



import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.korebap.app.biz.reply.ReplyDTO;
import com.korebap.app.biz.reply.ReplyService;
import com.korebap.app.view.util.LoginCheck;

import jakarta.servlet.http.HttpSession;


@Controller
public class DeleteReplyAction {

	@Autowired
	private ReplyService replyService;
	
	@Autowired
	private LoginCheck loginCheck;

	@RequestMapping(value="/deleteReply.do", method=RequestMethod.POST)
	public String deleteReply(ReplyDTO replyDTO,Model model, RedirectAttributes redirectAttributes) {
		// [ 댓글 삭제 ]

		System.out.println("************************************************************[com.korebap.app.view.reply deleteReply 시작]************************************************************");

		// 경로를 담을 변수
		String viewName;

		// 상세페이지로 이동시키기 위해 변수 선언
		int board_num = replyDTO.getReply_board_num();

		// 로그인 상태 확인
		String login_member_id = loginCheck.loginCheck();


		// 데이터 로그
		System.out.println("*****com.korebap.app.view.reply deleteReply member_id 확인 : ["+login_member_id+"]*****");
		System.out.println("*****com.korebap.app.view.reply deleteReply board_num 확인 : ["+board_num+"]*****");
		System.out.println("*****com.korebap.app.view.reply deleteReply reply_num 확인 : ["+replyDTO.getReply_num()+"]*****");


		if(login_member_id.equals("")) { // 만약 로그인 상태가 아니라면 
			System.out.println("*****com.korebap.app.view.reply deleteReply 로그인 세션 없음*****");

			// 로그인 안내 후 login 페이지로 이동시킨다
			model.addAttribute("msg", "로그인이 필요한 서비스입니다.");
			model.addAttribute("path", "loginPage.do");

			// 데이터를 보낼 경로
			viewName = "info";
		}
		else {
			System.out.println("*****com.korebap.app.view.reply deleteReply 로그인 세션 있음*****");

			// service에 삭제 요청 보낸다
			boolean flag = replyService.delete(replyDTO);

			if(flag) { // 삭제 성공시
				System.out.println("*****com.korebap.app.view.reply deleteReply 댓글 삭제 성공*****");

				redirectAttributes.addAttribute("board_num", board_num);

				viewName = "redirect:boardDetail.do";

			}
			else { // 삭제 실패시
				System.out.println("*****com.korebap.app.view.reply deleteReply 댓글 삭제 실패*****");

				model.addAttribute("msg", "댓글 삭제 실패. 다시 시도해주세요.");
				model.addAttribute("path", "boardDetail.do?board_num="+board_num);

				viewName = "info";
			}

		}
		
		System.out.println("*****com.korebap.app.view.reply deleteReply viewName ["+viewName+"]*****");
		
		
		System.out.println("************************************************************[com.korebap.app.view.reply deleteReply 종료]************************************************************");

		return viewName;

	}
}

 

package com.korebap.app.view.reply;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.korebap.app.biz.reply.ReplyDTO;
import com.korebap.app.biz.reply.ReplyService;
import com.korebap.app.view.util.LoginCheck;

import jakarta.servlet.http.HttpSession;


@Controller
public class WriteReplyAction {

	@Autowired
	private ReplyService replyService;
	
	@Autowired
	private LoginCheck loginCheck;

	@RequestMapping(value="/writeReply.do", method=RequestMethod.POST)
	public String writeReply(ReplyDTO replyDTO, Model model, RedirectAttributes redirectAttributes,
			@RequestParam int board_num) {
		// [댓글 작성]

		System.out.println("************************************************************[com.korebap.app.view.reply writeReply 시작]************************************************************");

		
		// 로그인 체크
		String login_member_id = loginCheck.loginCheck();

		// 경로를 저장하는 변수
		String viewName;

		// 데이터 로그
		System.out.println("*****com.korebap.app.view.review writeReply member_id 확인 : ["+login_member_id+"]*****");
		System.out.println("*****com.korebap.app.view.review writeReply DTO 확인 : ["+replyDTO+"]*****");
		System.out.println("*****com.korebap.app.view.review writeReply board_num 확인 : ["+board_num+"]*****");


		if(login_member_id.equals("")) { // 만약 로그인 상태가 아니라면 
			System.out.println("*****com.korebap.app.view.review writeReply 로그인 세션 없음*****");

			// 로그인 안내 후 login 페이지로 이동시킨다
			model.addAttribute("msg", "로그인이 필요한 서비스입니다.");
			model.addAttribute("path", "login.do");

			// 데이터를 보낼 경로
			viewName = "info";
		}
		else {
			System.out.println("*****com.korebap.app.view.review writeReply 로그인 세션 있음*****");

			// Service에게 DTO를 보내 댓글 insert 진행
			replyDTO.setReply_writer_id(login_member_id);
			replyDTO.setReply_board_num(board_num);
			boolean flag = replyService.insert(replyDTO);

			// 반환받은 값이 true라면
			if(flag) {
				// 댓글 작성 성공
				// 글 상세 페이지로 보내준다
				System.out.println("*****com.korebap.app.view.review writeReply 댓글 작성 성공*****");
				// 상품 상세 페이지로 보내줌
				// 리다이렉트시 쿼리 매개변수를 자동으로 URL에 포함
				// 쿼리 매개변수 == URL에서 ? 기호 뒤에 위치하는 key-value 쌍
				redirectAttributes.addAttribute("board_num", board_num);
				viewName = "redirect:boardDetail.do";
			}
			else {
				// 댓글 작성 실패
				// 실패 안내와 함께 글 상세 페이지로 보내준다.
				System.out.println("*****com.korebap.app.view.review writeReply 댓글 작성 실패*****");

				model.addAttribute("msg", "댓글 작성에 실패했습니다. 다시 시도해주세요.");
				model.addAttribute("path", "boardDetail.do?board_num="+board_num);
				viewName = "info";
			}

		}
		
		
		System.out.println("*****com.korebap.app.view.review writeReply viewName ["+viewName+"]*****");
		System.out.println("************************************************************[com.korebap.app.view.reply writeReply 종료]************************************************************");
		
		return viewName;

	}

}

 
 
 

Review

더보기
더보기

✨ Review (리뷰)

 

package com.korebap.app.view.review;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.korebap.app.biz.review.ReviewDTO;
import com.korebap.app.biz.review.ReviewService;
import com.korebap.app.view.util.LoginCheck;

import jakarta.servlet.http.HttpSession;


@Controller
public class DeleteReviewAction {

	@Autowired
	private ReviewService reviewService;
	
	@Autowired
	private LoginCheck loginCheck;

	@RequestMapping(value="/deleteReview.do", method=RequestMethod.POST)
	public String deleteReview(ReviewDTO reviewDTO, Model model, RedirectAttributes redirectAttributes) {
		// [ 리뷰 삭제 ]
		System.out.println("************************************************************[com.korebap.app.view.review deleteReview 시작]************************************************************");


		// 로그인 체크
		String login_member_id = loginCheck.loginCheck();
		// 페이지 경로 변수 설정
		String viewName;
		// 상세페이지로 이동시키기 위해 변수 선언
		int review_product_num = reviewDTO.getReview_product_num();


		// 데이터 로그
		System.out.println("*****com.korebap.app.view.review deleteReview member_mid 확인 : ["+login_member_id+"]*****");
		System.out.println("*****com.korebap.app.view.review deleteReview review_num 확인 : ["+reviewDTO.getReview_num()+"]*****");
		System.out.println("*****com.korebap.app.view.review deleteReview review_product_num 확인 : ["+review_product_num+"]*****");




		if(login_member_id.equals("")) { // 만약 로그인 상태가 아니라면 
			System.out.println("*****com.korebap.app.view.review deleteReview 로그인 세션 없음*****");

			// 로그인 안내 후 login 페이지로 이동시킨다
			model.addAttribute("msg", "로그인이 필요한 서비스입니다.");
			model.addAttribute("path", "loginPage.do");

			// 데이터를 보낼 경로
			viewName = "info";
		}
		else {
			System.out.println("*****com.korebap.app.view.review deleteReview 로그인 세션 있음*****");

			// M에게 보내 삭제 요청
			boolean flag = reviewService.delete(reviewDTO);

			if(flag) {
				System.out.println("*****com.korebap.app.view.review deleteReview 리뷰 삭제 성공 반환*****");

				// 상품 번호를 쿼리 매개변수로 추가
				redirectAttributes.addAttribute("product_num", review_product_num);		
				
				// 경로 설정
				viewName = "redirect:productDetail.do";

			}
			else {
				System.out.println("*****com.korebap.app.view.review deleteReview 리뷰 삭제 실패*****");

				// 로그인 안내 후 login 페이지로 이동시킨다
				model.addAttribute("msg", "리뷰 삭제에 실패했습니다. 다시 시도해주세요.");
				model.addAttribute("path", "productDetail.do?product_num="+review_product_num);

				// 경로 설정
				viewName = "info";
			}

		}
		
		System.out.println("*****com.korebap.app.view.reply deleteReview viewName ["+viewName+"]*****");

		System.out.println("************************************************************[com.korebap.app.view.review deleteReview 종료]************************************************************");
		
		return viewName;

	}

}

 

package com.korebap.app.view.review;




import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.korebap.app.biz.review.ReviewDTO;
import com.korebap.app.biz.review.ReviewService;
import com.korebap.app.view.util.LoginCheck;

import jakarta.servlet.http.HttpSession;


@Controller
public class UpdateReviewAction {

	@Autowired
	private ReviewService reviewService;

	@Autowired
	private LoginCheck loginCheck;
	
	@RequestMapping(value="/updateReview.do", method=RequestMethod.POST)
	public String updateReview(ReviewDTO reviewDTO, Model model,RedirectAttributes redirectAttributes) {

		// [ 리뷰 수정 ]

		System.out.println("************************************************************[com.korebap.app.view.review updateReview 시작]************************************************************");

		
		// 로그인 체크
		String login_member_id = loginCheck.loginCheck();

		// 경로를 저장하는 변수
		String viewName;
		// 상품 상세페이지로 보낼 때 필요한 상품 번호
		int review_product_num = reviewDTO.getReview_product_num();

		// DTO 데이터 로그
		System.out.println("***** com.korebap.app.view.review updateReview member_id 확인 : [" + login_member_id + "] *****");
		System.out.println("***** com.korebap.app.view.review updateReview review_product_num 확인 : [" + review_product_num + "] *****");
		System.out.println("***** com.korebap.app.view.review updateReview review_num 확인 : [" + reviewDTO.getReview_num() + "] *****");
		System.out.println("***** com.korebap.app.view.review updateReview review_star 확인 : [" + reviewDTO.getReview_star() + "] *****");
		System.out.println("***** com.korebap.app.view.review updateReview review_content 확인 : [" + reviewDTO.getReview_content() + "] *****");


		if(login_member_id.equals("")) { // 만약 로그인 상태가 아니라면 
			System.out.println("*****com.korebap.app.view.review updateReview 로그인 세션 없음*****");

			// 로그인 안내 후 login 페이지로 이동시킨다
			model.addAttribute("msg", "로그인이 필요한 서비스입니다.");
			model.addAttribute("path", "loginPage.do");

			// 데이터를 보낼 경로
			viewName = "info";
		}
		else {

			System.out.println("*****com.korebap.app.view.review updateReview 로그인 세션 있음*****");


			// DTO 객체를 보내 update 진행
			boolean flag = reviewService.update(reviewDTO); 

			if(flag) {
				System.out.println("*****com.korebap.app.view.review updateReview 리뷰 수정 성공*****");

				// 상품 상세 페이지로 보내줌
				// 리다이렉트시 쿼리 매개변수를 자동으로 URL에 포함
				// 쿼리 매개변수 == URL에서 ? 기호 뒤에 위치하는 key-value 쌍
				redirectAttributes.addAttribute("product_num", review_product_num);

				viewName = "redirect:productDetail.do";

			}
			else {
				System.out.println("*****com.korebap.app.view.review updateReview 리뷰 수정 실패*****");

				// 상품 상세 페이지로 보내줌
				model.addAttribute("msg", "리뷰 수정에 실패했습니다. 다시 시도해주세요.");
				model.addAttribute("path", "productDetail.do?product_num="+review_product_num);

				viewName = "info";
			}

		}
		System.out.println("*****com.korebap.app.view.wishlist updateReview viewName ["+viewName+"]*****");
		
		System.out.println("************************************************************[com.korebap.app.view.review updateReview 종료]************************************************************");
		return viewName;

	}

}

 

 

package com.korebap.app.view.review;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.korebap.app.biz.review.ReviewDTO;
import com.korebap.app.biz.review.ReviewService;
import com.korebap.app.view.util.LoginCheck;

import jakarta.servlet.http.HttpSession;

@Controller
public class WriteReviewAction{

	@Autowired
	private ReviewService reviewService;
	
	@Autowired
	private LoginCheck loginCheck;

	@RequestMapping(value="/writeReview.do", method=RequestMethod.POST)
	public String writeReview(ReviewDTO reviewDTO, Model model, RedirectAttributes redirectAttributes) {
		// [ 리뷰 작성 ]

		System.out.println("************************************************************[com.korebap.app.view.review writeReview 시작]************************************************************");

		
		// 로그인 체크
		String login_member_id = loginCheck.loginCheck();

		// 경로를 저장하는 변수
		String viewName;
		
		// 상품 상세페이지로 보낼 때 필요한 상품 번호
		int review_product_num = reviewDTO.getReview_product_num();

		// DTO 데이터 로그
		System.out.println("***** com.korebap.app.view.review updateReview member_id 확인 : [" + login_member_id + "] *****");
		System.out.println("***** com.korebap.app.view.review updateReview review_product_num 확인 : [" + review_product_num + "] *****");
		System.out.println("***** com.korebap.app.view.review updateReview review_num 확인 : [" + reviewDTO.getReview_num() + "] *****");
		System.out.println("***** com.korebap.app.view.review updateReview review_star 확인 : [" + reviewDTO.getReview_star() + "] *****");
		System.out.println("***** com.korebap.app.view.review updateReview review_content 확인 : [" + reviewDTO.getReview_content() + "] *****");



		if(login_member_id.equals("")) { // 만약 로그인 상태가 아니라면 
			System.out.println("*****com.korebap.app.view.review writeReview 로그인 세션 없음*****");

			// 로그인 안내 후 login 페이지로 이동시킨다
			model.addAttribute("msg", "로그인이 필요한 서비스입니다.");
			model.addAttribute("path", "login.do");

			// 데이터를 보낼 경로
			viewName = "info";
		}
		else {

			System.out.println("*****com.korebap.app.view.review writeReview 로그인 세션 있음*****");

			// Service를 통해 DB에 데이터를 insert
			reviewDTO.setReview_writer_id(login_member_id);
			boolean flag = reviewService.insert(reviewDTO);

			if(flag) {
				System.out.println("*****com.korebap.app.view.review writeReview 리뷰 작성 성공*****");

				// 상품 상세 페이지로 보내줌
				// 리다이렉트시 쿼리 매개변수를 자동으로 URL에 포함
				// 쿼리 매개변수 == URL에서 ? 기호 뒤에 위치하는 key-value 쌍
				redirectAttributes.addAttribute("product_num", review_product_num);
				viewName = "redirect:productDetail.do";

			}
			else {
				System.out.println("*****com.korebap.app.view.review writeReview 리뷰 작성 실패*****");

				model.addAttribute("msg", "리뷰 작성에 실패했습니다. 다시 시도해주세요.");
				model.addAttribute("path", "productDetail.do?product_num="+review_product_num);
				viewName = "info";
			}

		}
		
		System.out.println("*****com.korebap.app.view.wishlist writeReview viewName ["+viewName+"]*****");
		
		System.out.println("************************************************************[com.korebap.app.view.review writeReview 종료]************************************************************");
		return viewName;

	}

}

 
 

WishList

더보기
더보기

✨ WishList (위시리스트(찜))

 

package com.korebap.app.view.page;



import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.korebap.app.biz.wishlist.WishlistDTO;
import com.korebap.app.biz.wishlist.WishlistService;
import com.korebap.app.view.util.LoginCheck;



@Controller
public class WishListPageAction{
	
	@Autowired
	private WishlistService wishlistService;
	
	@Autowired
	private LoginCheck loginCheck; // 로그인 상태 확인 유틸리티 주입


	@RequestMapping(value="/wishListPage.do", method=RequestMethod.GET)
	public String wishListPage(WishlistDTO wishlistDTO,Model model) {
		// 위시리스트 목록 페이지
		System.out.println("************************************************************[com.korebap.app.view.page  wishListPage 시작]************************************************************");

		
		// 로그인 체크
		String login_member_id = loginCheck.loginCheck();
		
		
		// 데이터 로그
		System.out.println("*****com.korebap.app.view.page wishListPage 로그인 아이디 : ["+login_member_id+"]*****");
		
		if(login_member_id.equals("")) { // 만약 로그인 상태가 아니라면 
			System.out.println("*****com.korebap.app.view.page wishListPage 로그인 세션 없음*****");
			// 로그인 안내 후 login 페이지로 이동시킨다
			
			model.addAttribute("msg", "로그인이 필요한 서비스입니다.");
			model.addAttribute("path", "login.do");
			
			return "info";
		}
		else { // 만약 로그인 상태라면
			System.out.println("*****com.korebap.app.view.page wishListPage 로그인 세션 있음*****");

			// 세션에서 받아온 id 정보를 M에게 전달하기 위해 DTO 객체에 담아준다.
			wishlistDTO.setWishlist_member_id(login_member_id);
			
			// [위시리스트 전체 목록]
			// M에게 데이터를 보내주고, 결과를 List로 반환받는다.
			List<WishlistDTO> wishlist = wishlistService.selectAll(wishlistDTO);
			
			System.out.println("*****com.korebap.app.view.page wishListPage wishlist ["+wishlist+"]*****");

			
			// [위시리스트 개수]
			// M에게 데이터를 보내주고, 결과를 DTO로 반환받는다.
			wishlistDTO = wishlistService.selectOne(wishlistDTO);
			
			//int 타입 변수에 받아온 값을 넣어준다.
			int wishlist_count = wishlistDTO.getWishlist_cnt();
			
			System.out.println("*****com.korebap.app.view.page wishListPage wishlist_count ["+wishlist_count+"]*****");

			
			// V에게 전달해주기 위해 model 객체에 데이터를 저장한다.
			model.addAttribute("wishlist", wishlist); // 위시리스트 목록
			model.addAttribute("wishlist_count", wishlist_count); // 위시리스트 개수
			
		}
		
		
		System.out.println("************************************************************[com.korebap.app.view.page  wishListPage 종료]************************************************************");

		return "wishList";
	}

}

 

package com.korebap.app.view.wishlist;



import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.korebap.app.biz.wishlist.WishlistDTO;
import com.korebap.app.biz.wishlist.WishlistService;
import com.korebap.app.view.util.LoginCheck;

import jakarta.servlet.http.HttpSession;

@Controller
public class AddWishListAction {

	@Autowired
	private WishlistService wishlistService;

	@Autowired
	private LoginCheck loginCheck;

	@RequestMapping(value="/addWishList.do", method=RequestMethod.POST)
	public String addWishList(WishlistDTO wishlistDTO,Model model,RedirectAttributes redirectAttributes) {
		// [ 위시리스트 추가 ]
		
		System.out.println("************************************************************[com.korebap.app.view.wishlist addWishList 시작]************************************************************");


		// 로그인체크
		String login_member_id = loginCheck.loginCheck();

		// 경로를 저장하는 변수
		String viewName = "info";
		
		// 상품 상세페이지로 보낼 때 필요한 상품 번호
		int wishlist_product_num = wishlistDTO.getWishlist_product_num();


		// 데이터 로그
		System.out.println("*****com.korebap.app.view.wishlist addWishList member_id 확인 : ["+login_member_id+"]*****");
		System.out.println("*****com.korebap.app.view.wishlist addWishList wishlist_product_num 확인 : ["+wishlist_product_num+"]*****");


		if(login_member_id.equals("")) { // 만약 로그인 상태가 아니라면 
			System.out.println("*****com.korebap.app.view.wishlist addWishList 로그인 세션 없음*****");

			// 로그인 안내 후 login 페이지로 이동시킨다
			model.addAttribute("msg", "로그인이 필요한 서비스입니다.");
			model.addAttribute("path", "loginPage.do");

		}
		else { // 만약 로그인 상태라면
			System.out.println("*****com.korebap.app.view.wishlist addWishList 로그인 상태 시작*****");


			// 로그인한 회원의 ID를 DTO 객체에 넣어준다.
			wishlistDTO.setWishlist_member_id(login_member_id);

			// 중복 확인을 위해 M에게 데이터를 보내, 해당 회원의 위시리스트를 반환받는다.
			List<WishlistDTO> wishlist = wishlistService.selectAll(wishlistDTO);

			System.out.println("*****com.korebap.app.view.wishlist addWishList 데이터 확인 wishlist : ["+wishlist+"]*****");


			// 위시리스트 중 해당 상품 번호가 있는지 확인
			for (WishlistDTO item : wishlist) {
				if (item.getWishlist_product_num() == wishlist_product_num) {
					// 원하는 상품 번호를 찾았을 때 처리
					System.out.println("*****com.korebap.app.view.wishlist addWishList 동일한 상품 위시리스트에 존재 : ["+item.getWishlist_product_num()+"]*****");

					// 실패 안내 (메세지 view에 전달)
					redirectAttributes.addFlashAttribute("msg", "이미 추가된 상품입니다.");
					// 어디로 보내는지 경로를 작성한다
					return"redirect:productDetail.do?product_num=" + wishlist_product_num;
				}
				System.out.println("*****com.korebap.app.view.wishlist addWishList 중복 상품번호 찾기 종료*****");
			}


			// M에게 받은 위시리스트 중 없다면 insert 진행
			// M에게 DTO 객체를 보내 insert 진행하고, 결과를 boolean 타입으로 반환받는다.
			boolean flag = wishlistService.insert(wishlistDTO);

			System.out.println("*****com.korebap.app.view.wishlist addWishList insert 결과 ["+flag+"]*****");

			if(flag) {// 만약 true 반환받았다면 
				System.out.println("*****com.korebap.app.view.wishlist addWishList insert 성공*****");
				// 상품 상세페이지로 이동

				// addFlashAttribute : 주로 리다이렉트 후에 한 번만 사용할 데이터를 전달할 때 사용 (ex.성공 메시지, 에러 메시지 등)
				// addAttribute :  뷰에 직접 전달하고자 하는 데이터를 설정
				redirectAttributes.addFlashAttribute("msg", "상품이 찜 목록에 추가되었습니다.");
				redirectAttributes.addAttribute("product_num", wishlist_product_num);

				viewName = "redirect:productDetail.do";

			}
			else { // 만약 false 반환받았다면
				System.out.println("*****com.korebap.app.view.wishlist addWishList insert 실패*****");
				// 실패 안내
				model.addAttribute("msg", "위시리스트 추가에 실패했습니다. 다시 시도해주세요.");
				// 상품 상세페이지로 이동
				model.addAttribute("path", "productDetail.do?product_num="+wishlist_product_num);

				// 어디로 보내는지 경로를 작성한다
				// 보낼 데이터가 있다면 포워드, 없다면 리다이렉트 방식으로 전달한다.
				viewName = "info";
			}
		}
		System.out.println("*****com.korebap.app.view.wishlist addWishList viewName ["+viewName+"]*****");
		System.out.println("************************************************************[com.korebap.app.view.wishlist addWishList 종료]************************************************************");

		return viewName;

	}

}

 
 
현재는 Mapping을 모두 @RequestMapping으로 해주고, 
메서드 타입을 모두 지정해 둔 상태인데 이를 @GetMapping / @PostMapping으로 변경할 계획이다.
 
GET
- 주로 R타입 (민감 정보 제외 - ex. 로그인)
- 데이터 단순 조회 목적일 때 (URL에 담겨도 관계없는 정보)
- 단순 페이지 이동인 경우
 
POST
- 주로 CUD 타입 (DB를 거치는 것들)
- GET에 비해선 상대적으로 보안이 좋기 때문에 
  안정적인 데이터 처리가 필요한 경우