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
ViewandController - inside JSP, both
HTMLandJavacode are used 👍🏻 easy implementation
👎🏻 when app starts getting bigger, reduce reusability and code readability
✔️ MVC 2 ➡️ Spring
- request sent to
Controller(Servlet) ControllerandViewis 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 Servletrecieves this request, askHandler Mappingto findcontrollerthat controls that url.- Send request to
Controller, and setModelthat is required to send. Modelaccessesdatabaseto fetch data for page with query.Controllerresponds withModel information.ControllercompletesModeland sends toDispatcher Servlet.Controlleralso tellsDispatcher Servletwhatviewhas to be rendered.Dispatcher Servletrecieves view file fromView resolverthat matches the request- Send
Modeltoview pagefile and complete the page to send to client - Response
view fileto 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
controllershould manage therequest url, send it todispatcher servlet - for controller to
mapurl, uses@RequestMapping - the handler finds this url for
dispatcher servlet
✔️ Controller
- backend controller for managing request
- return
modelresult todispatcher servlet
✔️ View Resolver
- decides
viewof 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.