Câu hỏi phỏng vấn Spring
Câu hỏi

What is Spring MVC framework?

Câu trả lời

Spring MVC is a comprehensive Java framework that implements the Model-View-Controller (MVC) design pattern and provides a robust configuration model for building web applications. It is part of the larger Spring Framework, an extensive programming and configuration model for modern Java-based enterprise applications.

Core Components of Spring MVC

  1. Model: The Model component in Spring MVC encapsulates the application data and generally consists of POJO (Plain Old Java Objects) that represent the data of the application. The model objects hold the data and are not concerned with user interface or data presentation, allowing for a clean separation of concerns[2][6][8].

  2. View: The View is responsible for rendering the Model data, and it generates HTML content which the client's browser can interpret. Spring MVC supports various view technologies including traditional JSPs, Velocity templates, Thymeleaf, and more. The View resolves the data presented by the Model to the user, and can be easily manipulated to present different aspects of the data[2][6][8].

  3. Controller: The Controller acts upon both Model and View. It controls the data flow into model object and updates the view whenever data changes; it keeps view and model separate[2][6][8].

DispatcherServlet

At the heart of Spring MVC is the DispatcherServlet that acts as the front controller of the framework. It is responsible for orchestrating the whole process of handling a request, from receiving the request to sending the response back to the client. The DispatcherServlet does this by delegating responsibilities to various components such as controllers, view resolvers, and other specialized objects[2][6][7].

Workflow of a Spring MVC Application

  1. Receive Request: The DispatcherServlet receives an HTTP request.
  2. Delegate Request: Based on the URL, the DispatcherServlet delegates the request to a specific controller.
  3. Process Request: The controller processes the request by calling the appropriate service methods and returns a ModelAndView object which contains model data and view name.
  4. Resolve View: The DispatcherServlet consults the ViewResolver to load the view template.
  5. Render View: Once the view is instantiated, the DispatcherServlet renders the view by filling the model data into the view template.
  6. Return Response: The response is then returned to the client[2][6][7].

Advantages of ...

junior

junior

Gợi ý câu hỏi phỏng vấn

expert

I want to know what actually happens when you annotate a method with @Transactional?

junior

What is Spring Security?

middle

Does Spring Bean provide thread safety?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào