
์๋ก
MVC ํจํด์ ๋ฉด์ ๋ณผ ๋ ๋จ๊ณจ ์ง๋ฌธ์ด๋ผํด๋ ๊ณผ์ธ์ด ์๋๋งํผ ์์ฃผ ์ธ๊ธ๋๋ ์ฃผ์ ์ด๋ค. Model, View, Controller ๋ผ๋ ์๋ฏธ๋ผ๋ ๊ฒ์ ์๊ณ ์์ด๋ ๊ทธ ์๋ฏธ๋ฅผ ์์ธํ ์ค๋ช ํ๋ ๊ฒ์ ํญ์ ์ฝ์ง ์๋ค. ๋ฐ๋ผ์ ์ด๋ฒ ํฌ์คํ ์์๋ ์คํ๋ง MVC์ ๋ํด ์์ธํ ์ดํด๋ณด๊ณ ์ ํ๋ค.
MVC ํจํด์ด๋?
- MVC ํจํด์ ์ดํ๋ฆฌ์ผ์ด์ ์ Model, View, Controller๋ก ๊ตฌ๋ถํ์ฌ ์์ ์ ๋ถ๋ฆฌํ๋ ๊ฐ๋ฐ ๋ฐฉ๋ฒ๋ก
- ์๋ก ๊ฐ์ ๊ฒฐํฉ๋ ์ต์ํ + ์ ์ง๋ณด์์ฑ์ ๋์ด๋ฉฐ + ๊ฐ๋ฐ์ ํจ์จ์ฑ ํฅ์
- Model(๋ชจ๋ธ) : ๋น์ฆ๋์ค ๋ก์ง์ ๋ด๊ณ ์๋ ๋ฐ์ดํฐ ์ฒ๋ฆฌ ๊ณ์ธต, DB์ ์ง์ ์ฐ๊ฒฐ๋๋ DAO, Entity, Service ๋ฑ์ด ์ฌ๊ธฐ์ ํด๋น
- View(๋ทฐ) : ์ฌ์ฉ์๊ฐ ์ค์ ๋ก ๋ณด๋ ํ๋ฉด(UI), Model์์ ๋ฐ์ ๋ฐ์ดํฐ๋ฅผ ํ์ํจ → HTML, JSP, JSON ๋ฑ ๋ค์ํ ํํ๋ก ์ถ๋ ฅ
- Contorller(์ปจํธ๋กค๋ฌ) : ํด๋ผ์ด์ธํธ ์์ฒญ์ ๋ฐ์ ์ด๋ค ๋น์ฆ๋์ค ๋ก์ง์ ์คํํ ์ง ๊ฒฐ์ ํ๊ณ ๊ทธ ๊ฒฐ๊ณผ๋ฅผ view์ ์ ๋ฌ
//Controller(์ปจํธ๋กค๋ฌ) ์์
@Controller
public class MemberController {
@GetMapping("/members")
public String getMembers(Model model) {
List<Member> members = memberService.findAll();
model.addAttribute("members", members);
return "memberList"; // View ์ด๋ฆ(jsp๋ htmlํ์ ๋ฑ)
}
}
MVC ๋ฑ์ฅ ์ด์
- ์ด์ฐฝ๊ธฐ ํ๋ก๊ทธ๋จ ํ๋ก๊ทธ๋จ ๊ตฌ์กฐ์ ๋ฌธ์ ์
- ์ด๊ธฐ์๋ ๋๋ถ๋ถ์ ์ ํ๋ฆฌ์ผ์ด์ ์ด ๋ชจ๋ ธ๋ฆฌ์ค ํํ์์ ์ฆ
// ํ๋์ ํ์ผ์ ๋ชจ๋ ๊ฑธ ์ฒ๋ฆฌ
public void onClick() {
connectDB();
getData();
calculate();
renderScreen();
}
- ์ด๋ ๊ฒ ๋ฐ์ดํฐ ์ฒ๋ฆฌ, ๋น์ฆ๋์ค ๋ก์ง, UI ํ์๊ฐ ํ ์ฝ๋ ์์์ ์ด๋ฃจ์ด์ง
→ ์ ์ง๋ณด์ ์ด๋ ค์, ์ฌ์ฌ์ฉ ์ด๋ ค์, ํ ์คํธ ์ด๋ ค์, ํ์ ์ด ๋นํจ์จ์ ๋ฑ ๋ค์ํ ๋ฌธ์ ๋ฐ์
- ๊ทธ๋์ ๋ฑ์ฅํ ๊ฒ์ด MVC ํจํด
- Controller์์ ์ฌ์ฉ์ ์
๋ ฅ์ ์ฒ๋ฆฌํจ, Model์์ ๋ฐ์ดํฐ๋ฅผ ์ฒ๋ฆฌํจ, View์์ ๋ฐ์ดํฐ๋ฅผ ํ์ํจ
→ UI, ๋น๋์ค ๋ก์ง, ๋ฐ์ดํฐ ๊ด๋ฆฌ๋ฅผ ๊ฐ๊ฐ ๋ ๋ฆฝ์ ์ผ๋ก ๋ถ๋ฆฌ์์ผ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํจ
MVC ๊ตฌ์กฐ

- ์ฌ์ฉ์์ ๋ชจ๋ ์์ฒญ์ DispatcherServlet(FrontController)์ ํตํด ์ฒ๋ฆฌ๋จ
- DispatcherServlet์ ๋ฐ์ ์์ฒญ์ HandlerMapping์ผ๋ก ์ ๋ฌ
- DispatcherServlet์ด HandlerAdapter๋ฅผ ์ด์ฉํด์ ํด๋นํ๋ ์ปจํธ๋กค๋ฌ๋ฅผ ์๋์ํด
- ์ค์ ๊ฐ๋ฐ์๋ Controller์ ์์ฒญ์ ์ฒ๋ฆฌํ๋ ๋น๋์ค ๋ก์ง์ ์์ฑํ๊ณ View์ ์ ๋ฌํด์ผํ๋ ๋ฐ์ดํฐ๋ฅผ Model์ด๋ผ๋ ๊ฐ์ฒด์ ๋ด์์ ์ ๋ฌํจ
- Controller๋ View์ ์ด๋ฆ์ DispatcherServlet์ ๋ฐํ
- DispatcherServlet์ ViewResolver๋ฅผ ํธ์ถํด Controller๊ฐ ๋ฐํํ View ์ด๋ฆ์ ๊ธฐ๋ฐ์ผ๋ก ํด๋น๋๋ View๋ฅผ ์ฐพ์์ค
- DispatcherServlet์ด View์ ์ฒ๋ฆฌ ๊ฒฐ๊ณผ๋ฅผ ๋๊ฒจ ์ต์ข ๊ฒฐ๊ณผ๋ฅผ ๋ณด์ฌ์ฃผ๋๋ก ์์ฒญ
- View๋ ์ค์ ๋ก ์๋ต์ ๋ณด๋ด์ผ ํ๋ ๋ฐ์ดํฐ๋ฅผ jsp, html๋ฑ์ ์ด์ฉํด ์์ฑํ๋ ์ญํ ์ ํจ, ๋ง๋ค์ด์ง ์๋ต์ DispatcherServlet์ ํตํด ์ ๋ฌ
- ์ ๊ทธ๋ฆผ์ด ์ดํดํ๊ธฐ ์ด๋ ต๋ค๋ฉด ์๋ ๊ทธ๋ฆผ ์ฐธ๊ณ (๊ทธ๋ฆผํ์ผ๋ก ๊ทธ๋ ค์ ํ๋ฆฌํฐ ๋ฎ์)

์ค์ ํ์ผ
- ์คํ๋ง MVC๋ ์คํ๋ง์ ์๋ธ ํ๋ก์ ํธ์ → ๋ณ๋์ ์ค์ ์ด ์กด์ฌ
| ์ค์ ํ์ผ | ์ค๋ช |
| web.xml | ์ค์ ์ ์ํ ์ค์ ํ์ผ, WAS ๊ตฌ๋๊ณผ ๊ด๋ จ๋ ์ค์ |
| root-context.xml | ์ผ๋ฐ Java ์์ญ์ ๋ํ ์ค์ |
| servlet-context.xml | WEB ๊ด๋ จ ์์ญ์ ๋ํ ์ค์ |
> web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee https://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- ๋ชจ๋ ์๋ธ๋ฆฟ๊ณผ ํํฐ๊ฐ ๊ณต์ ํ Spring์ root-context.xmlํ์ผ์ ์์น ์ง์ -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<!-- ์์์ ์ ์ํ context-param์ ์ฝ๊ณ ์ ์ญ Bean๋ค์ ๋ก๋ฉํ๋ ์ญํ -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- ํด๋ผ์ด์ธํธ ์์ฒญ์ ๋ฐ์ ์ ์ ํ Controller์ ๋ถ๋ฐฐํ๊ณ ๊ฒฐ๊ณผ๋ฅผ View๋ก ์ฐ๊ฒฐ -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- appServlet(DispatcherServlet)์ด ๋ชจ๋ ์์ฒญ(/)์ ์ฒ๋ฆฌํ๋๋ก ์ง์ -->
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
> root-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
</beans>
- ์ผ๋ฐ Java ์์ญ์ ๋ํด ์ค์ ํ๋ ํ์ผ → Service๋ DAO, DB ์ฐ๋์ ์ํด ์ฌ์ฉํ๋ DataSource ๋ฑ์ ๋ฑ๋กํ๋ ์ฝ๋๊ฐ ํฌํจ๋จ
> servlet-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
<!-- @Controller, @RequestMapping, @ResponseBody ๊ฐ์ Spring MVC ์ด๋
ธํ
์ด์
๊ธฐ๋ฐ ๊ธฐ๋ฅ๋ค์ ํ์ฑํ -->
<annotation-driven />
<!-- /resources/** ๊ฒฝ๋ก๋ก ์์ฒญ๋ ์ ์ ํ์ผ(CSS, ์ด๋ฏธ์ง ๋ฑ)์ ์น ์ ํ๋ฆฌ์ผ์ด์
์ /resources/ ํด๋์์ ์ฐพ์ ์๋น -->
<resources mapping="/resources/**" location="/resources/" />
<!-- ์ปจํธ๋กค๋ฌ์์ ๋ฐํํ๋ ๋ทฐ ์ด๋ฆ์ ์ค์ JSP ํ์ผ ๊ฒฝ๋ก๋ก ๋ณํํด์ฃผ๋ ๋ทฐ ๋ฆฌ์กธ๋ฒ(ViewResolver) ์ค์ -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<!-- com.controller ํจํค์ง ๋ด์ ํด๋์ค ์ค @Controller, @Service, @Component, @Repository ๋ฑ์ ๊ฐ์ง ํด๋์ค๋ค์ ์๋์ผ๋ก Bean์ผ๋ก ๋ฑ๋ก -->
<context:component-scan base-package="com.controller" />
</beans:beans>
์ ๋ฆฌ
| ์ญํ | ์์ | ์ฃผ์ ๊ธฐ๋ฅ | |
| Model | ๋ฐ์ดํฐ์ ๋น์ฆ๋์ค ๋ก์ง์ ๋ด๋น | Service, Repository, Entity, DTO | - ๋ฐ์ดํฐ ์ฒ๋ฆฌ - DB ์ ๊ทผ - ๋น์ฆ๋์ค ๊ท์น |
| View | ์ฌ์ฉ์์๊ฒ ๋ณด์ฌ์ง๋ UI | JSP, Thymeleaf, HTML, JSON | - ํ๋ฉด ์ถ๋ ฅ - ๋ฐ์ดํฐ๋ฅผ ์ฌ์ฉ์์๊ฒ ํ์ |
| Controller | ์ฌ์ฉ์์ ์์ฒญ ์ฒ๋ฆฌ ๋ฐ ํ๋ฆ ์ ์ด | @Controller, @RequestMapping | - ์ฌ์ฉ์ ์
๋ ฅ ์์ - Model ํธ์ถ - View๋ก ์ด๋ ๊ฒฐ์ |
Reference
https://amy-it.tistory.com/106
[Spring] ์คํ๋ง MVC์ ๊ธฐ๋ณธ ๊ตฌ์กฐ
๋ชฉ์ฐจ MVC ํจํด์ด๋? MVC ํจํด์ ์ดํ๋ฆฌ์ผ์ด์ ์ ์ธ ๊ฐ์ง ์์ญ, ์ฆ ๋ชจ๋ธ(Model), ๋ทฐ(View), ์ปจํธ๋กค๋ฌ(Controller)๋ก ๊ตฌ๋ถํ์ฌ ์์ ์ ๋ถ๋ฆฌํ๋ ์น ์ดํ๋ฆฌ์ผ์ด์ ๊ฐ๋ฐ ๋ฐฉ๋ฒ๋ก ์ผ๋ก์, ์๋ก ๊ฐ์ ๊ฒฐํฉ๋๋ฅผ ์ต
amy-it.tistory.com
https://imgzon.tistory.com/137
[Spring] MVC ํจํด, ์คํ๋ง MVC ๊ตฌ์กฐ ์ดํด
1. ๊ฐ์ ์ด๋ฒ ๊ฒ์๋ฌผ์์๋ MVC ํจํด์ ๋ํ ์๊ฐ, ์ฅ์ ์ ๋ํด์ ์ค๋ช ํ ๊ฒ์ด๋ค. ๊ทธ ํ, ์คํ๋ง์ ์ด MVC ๊ตฌ์กฐ๋ฅผ ์ด๋ป๊ฒ ๊ตฌํํ์๋์ง๋ฅผ ์์๋ณด๊ธฐ์ํด ์ด์ ๋น์ทํ MVC ํ๋ ์์ํฌ๋ฅผ ๋ง๋ค์ด ๋ณผ ๊ฒ
imgzon.tistory.com
์คํ๋ง MVC ํจํด ์๋ฏธ์ ๊ตฌ์กฐ [์ ๋ฆฌ]
์๋ ํ์ธ์, ์ค์ฝ๋ฆฌ์์ ๋๋ค.์ค๋์ ์คํ๋ง MVC ํจํด์ ์๋ฏธ์ ๊ตฌ์กฐ์ ๋ํด์ ์ดํด๋ณด๊ฒ ์ต๋๋ค. MVC ํจํด ์๋ฏธMVC๋ Model View Controller์ ์ค์๋ง์ ํ๋ฆฌ์ผ์ด์ ๊ฐ๋ฐ ์์ญ์ Model, View, Controller๋ก ๊ตฌ๋ถ
skorea6.tistory.com
'๐ Spring' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| [Spring] 05.์คํ๋ง ORM๊ณผ JPA - Hibernate (11) | 2025.07.24 |
|---|---|
| [Spring] 03.DI์ IoC ๊ฐ๋ ๋ฐ ์ด์ ๋ฆฌ (1) | 2024.04.15 |
| [Spring] 02.AOP๊ฐ๋ , Aspectํน์ง ์ด์ ๋ฆฌ (1) | 2024.01.04 |
| [Spring] 01.@Autowired,@Resource,@Inject ์ฐจ์ด (6) | 2023.11.20 |