Spring MVC Flashcards
What is Spring MVC?
A web framework in Spring for building web applications using the Model-View-Controller architecture.
What annotation is used to define a controller in Spring MVC?
@Controller.
What is the use of the @RequestMapping annotation?
It maps HTTP requests to handler methods in controllers.
How do you return JSON data from a Spring MVC controller?
By using @RestController or adding @ResponseBody to methods returning JSON.
What is @RestController in Spring MVC?
It combines @Controller and @ResponseBody for RESTful web services.
How can you handle form data in Spring MVC?
Using @ModelAttribute or @RequestParam in the controller methods.
What is the difference between @RequestParam and @PathVariable?
@RequestParam extracts query parameters, while @PathVariable extracts values from the URI path.
What is a ViewResolver in Spring MVC?
A component that resolves logical view names to actual view implementations, like JSP or Thymeleaf.
How do you handle exceptions in Spring MVC?
Using @ExceptionHandler in a controller or a global exception handler with @ControllerAdvice.
What is the DispatcherServlet in Spring MVC?
The front controller in Spring MVC that handles all incoming web requests and delegates them to the appropriate controllers.