🍃 Spring

왜 Spring Boot는 가벼운가? MVC 구조 변화로 이해하기 (JSP/서블릿 MVC → Spring MVC → Spring Boot)

보배 진 2026. 1. 19. 10:03

1. [A] FrontController에서 command 추출

2. [B] ActionFactory 한테서 command에 맞는 [C] Action 을 반환 받음

3. 어디로/어떻게 갈지보고 페이지 사용자에게 서비스

 

[A] 

FrontController라고도 불리는

유일한 서블릿이고

DispatcherServlet이라고 한다

 

[B]

ActionFactory

HandlerMapping

팩토리 : 싱글톤 유지

Spring Boot에서는 @GetMapping("/index"), @PostMapping("/index")

 

[C]

JSP의 Action이

스프링에서는 Controller이다

컨트롤러의 역할은 사용자의 요청 정보를 추출해서, 어디로/어떻게 갈지 반환

 JSP에서 이렇게 함 ▶ request, response 인자           ▶ ActionForward(JS) ➡ ModelAndView(프레임워크) ➡ (부트)

VO == DTO 

Command 객체

 

 

 

🔹 변경 전 (Spring MVC – ModelAndView)

package com.example.controller.member;

import org.jspecify.annotations.Nullable;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import com.example.biz.board.impl.BoardDAO;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

public class LogoutController implements Controller {

	@Override
	public @Nullable ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ModelAndView mav = new ModelAndView();
		
		if(true) {
			mav.addObject("datas", new BoardDAO().getBoardList(null)); // 경량화
			mav.setViewName("redirect:main.do");
		}
		else {
			mav.setViewName("login");
		}
		return mav;
	}
}

 

특징

▪ request, response 직접 사용

▪ ModelAndView 객체 생성

▪ 개발자가 new를 직접함

즉, MVC 구조는 맞지만 무겁다

 

 

 

 

🔹 변경 후 (Spring Boot – 경량화)

package com.example.controller.member;

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

import com.example.biz.member.MemberDTO;
import com.example.biz.member.impl.MemberDAO;

import jakarta.servlet.http.HttpSession;

@Controller
public class LogoutController {
	
	/*
	 인지로 사용자의 정보를 받는다 : request, response 를 사용했는데 
	 jakarta.servlet에서 오는 인자를 사용하지 않아도 된다 = 경량화
	 
	 포워드 고정이기 때문에 어떻게 갈지는 명시하지 않고
	 어디로 갈지만 알려준다
	 
	 중요 ▶▶ command 객체
	 만드는 방식을 우리도 사용하면 안돼?? 해서
	 같이 사용하는게 DAO, Session
	*/
	@RequestMapping(value="/index", method=RequestMethod.GET)
	public String test(MemberDTO memberDTO, MemberDAO memberDAO, HttpSession session) {
		memberDTO = memberDAO.getMember(memberDTO);
		
		if(memberDTO == null) {
			// 로그인 실패
		} else {
			// 로그인 성공
		}
		return "어디로 갈지"; // 객체를 반환하다가 String을 반환하게 됨 = 경량화
	}
}

@Controller 어노테이션을 명시하고

인자를 강제하지 않아 = 경량화

어디로 갈지만 명시 = 경량화

부트로 넘어오면서 부터는 자유도가 높아진다

 

GET 매핑

변경전 : @RequestMapping(value="/index", method=RequestMethod.GET)

변경후 : @GetMapping("/index")

하지만 변경된지 얼마 안되었기 때문에, 변경전 코드를 사용해보도록 하겠습니다

 

 

사용자의 요청 정보 추출을 어떻게? command 객체를 사용할 것이다

DTO의 setter이름과 view의 이름이 같아야 한다

command객체의 범위에 DTO 뿐 아니라 DAO도 들어간다

new를 개발자가 아닌 스프링이 하도록 command 객체를 활용하는 것이다

command 객체를 만들 때 DAO도 만들어줘라

같은 방법으로 HttpSession session도  command 객체로 활용가능하다

 

 

 

그런데 Command 객체 생성 방식으로 DAO를 생성하는게 맞을까? 

 

 

 

 

 

 

참고 : 사용자 요청 정보

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>표지페이지</title>
</head>
<body>

	<form action="login" method="POST">
		<table border="1">
			<tr>
				<td>아이디</td>
				<td><input type="text" name="mid" required></td>
			</tr>
			<tr>
				<td>비밀번호</td>
				<td><input type="password" name="mpw" required></td>
			</tr>
			<tr>
				<td colspan="2"><input type="submit" value="로그인"></td>
			</tr>
		</table>
	</form>

</body>
</html>

사용자는 mid, mpw 가 있고, request.mid 이런식으로 사용을 했다