MVC, MVC Design Pattern
✅ MVC
Model / View / Controller
- 소프트웨어 설계 패턴 중 하나
- 앱을
모델
,사용자 인터페이스
,비즈니스 로직
으로 구분하여 개발
✅ MVC Design Pattern
✔️ Model
- business logic
- database
- respond to request for information from other components
✔️ View
- Display data from Model to user
- output of request
- send user input to Controller
✔️ Controller
- intermediary between Model and View
- application logic: input validation, data transformation
💡 https://www.geeksforgeeks.org/mvc-design-pattern/
MVC 1 🆚 MVC 2
✔️ JSP
Jakarta Server Pages
HTML code + Java code and create dynamic web page
✔️ MVC 1
- JSP manages both
View
andController
- inside JSP, both
HTML
andJava
code are used 👍🏻 easy implementation
👎🏻 when app starts getting bigger, reduce reusability and code readability
✔️ MVC 2 ➡️ Spring
- request sent to
Controller(Servlet)
Controller
andView
is seperate- JSP: only manage
View
- Servelt: manage
controller
- JSP: only manage
- can debug only the necessary component
- Spring Framework
✅ What happens in MVC when client request server through url?
- When client requests url, web browser sends request to
spring
Dispatcher Servlet
recieves this request, askHandler Mapping
to findcontroller
that controls that url.- Send request to
Controller
, and setModel
that is required to send. Model
accessesdatabase
to fetch data for page with query.Controller
responds withModel information
.Controller
completesModel
and sends toDispatcher Servlet
.Controller
also tellsDispatcher Servlet
whatview
has to be rendered.Dispatcher Servlet
recieves view file fromView resolver
that matches the request- Send
Model
toview page
file and complete the page to send to client - Response
view file
to client
✔️ Dispatcher Servlet
- manage all request from HTTP protocol
- considered to be front controller
- centralized management of all requests through servelt container with http
✔️ Handler Mapping
- finds which
controller
should manage therequest url
, send it todispatcher servlet
- for controller to
map
url, uses@RequestMapping
- the handler finds this url for
dispatcher servlet
✔️ Controller
- backend controller for managing request
- return
model
result todispatcher servlet
✔️ View Resolver
- decides
view
of controller result
✅ Filter
java class that is executed by Servlet container check each incoming HTTP request and HTTP response
- associated with Servlet API
✅ HandlerIntercepter
- unique to spring
- operate after filter
- appropriate for pre-processing duties
- authorization checks
Filter 🆚 HandlerIntercepter
- filter 🆚 handler interceptor: difference in when it is operated
- but both before request going into controller
- both operate in Dispatcher Servlet
This post is licensed under CC BY 4.0 by the author.