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

What is Controller in Spring MVC framework?

Câu trả lời

In the Spring MVC framework, a Controller is a critical component that manages the flow of data between the Model and the View, handling user requests and defining application behavior. It acts as an intermediary, processing incoming requests, performing operations on the model, and returning a view to the user.

Key Characteristics of a Controller in Spring MVC:

  1. Annotation-Based Configuration: Controllers in Spring MVC are typically defined using the @Controller annotation. This annotation marks a class as a Controller, which can handle HTTP requests. This is part of the broader annotation-based configuration that Spring supports to promote a cleaner and more concise setup compared to XML configurations[1][2][3][4][5].

  2. Request Handling: Controllers use @RequestMapping and other related annotations like @GetMapping, @PostMapping, etc., to map URLs to corresponding methods within the controller. These methods define how different types of requests are handled[1][2][3][4][5].

  3. Integration with the DispatcherServlet: The DispatcherServlet plays a central role in Spring MVC as the front controller. It delegates requests to appropriate controllers based on the URL and other factors. The @Controller classes work in conjunction with this servlet to handle requests efficiently[1][2].

  4. Flexible Method Signatures: Spring MVC controllers support flexible method signatures. They can return different types of objects such as ModelAndView, String (view name), ResponseEntity, or even directly write to the response body using @ResponseBody[2][4].

  5. Model Manipulation: Controllers can add attributes to the model, which are then accessible within the view...

middle

middle

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

middle

What is the typical Bean life cycle in Spring Bean Factory Container?

senior

What are inner beans in Spring?

senior

What is the default scope in the web context?

Bình luận

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

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