Post

MVC, MVC Design Pattern

MVC

Model / View / Controller

  • 소프트웨어 설계 패턴 중 하나
  • 앱을 모델, 사용자 인터페이스, 비즈니스 로직으로 구분하여 개발

✅ MVC Design Pattern

Screenshot 2024-08-10 at 12 57 00

✔️ 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

Screenshot 2024-08-10 at 13 07 22

  • JSP manages both View and Controller
  • inside JSP, both HTML and Java code are used 👍🏻 easy implementation
    👎🏻 when app starts getting bigger, reduce reusability and code readability

✔️ MVC 2 ➡️ Spring

Screenshot 2024-08-10 at 13 08 44

  • request sent to Controller(Servlet)
  • Controller and View is seperate
    • JSP: only manage View
    • Servelt: manage controller
  • can debug only the necessary component
  • Spring Framework

✅ What happens in MVC when client request server through url?

Screenshot 2024-08-06 at 11 36 50

Screenshot 2024-08-10 at 13 17 31

  1. When client requests url, web browser sends request to spring
  2. Dispatcher Servlet recieves this request, ask Handler Mapping to find controller that controls that url.
  3. Send request to Controller, and set Model that is required to send.
  4. Model accesses database to fetch data for page with query.
  5. Controller responds with Model information. Controller completes Model and sends to Dispatcher Servlet. Controller also tells Dispatcher Servlet what view has to be rendered.
  6. Dispatcher Servlet recieves view file from View resolver that matches the request
  7. Send Model to view page file and complete the page to send to client
  8. 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 the request url, send it to dispatcher 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 to dispatcher 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.