Spring MVC
Spring MVC
o Model 1 architecture uses JSP (or HTML) to handle both presentation and business
logic. It lacks a clear separation between concerns, making it harder to maintain.
o @Controller
o @GetMapping("/home")
o }
o }
6. What is a ViewResolver?
o A ViewResolver maps a logical view name to the actual view (JSP, Thymeleaf, etc.).
7. What is Model?
8. What is ModelAndView?
o A holder for both Model and View in a single return value. It contains the data and
the view name.
9. What is a RequestMapping?
o The central front controller in Spring MVC that handles all incoming requests and
routes them to the appropriate controller.
o <servlet>
o <servlet-name>dispatcher</servlet-name>
o <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
o </servlet>
o <servlet-mapping>
o <servlet-name>dispatcher</servlet-name>
o <url-pattern>/</url-pattern>
o </servlet-mapping>
o An object used to hold form data and bind it to a Java object in Spring MVC.
o By using JSR-380/JSR-303 annotations like @NotNull, @Size, etc., along with @Valid
in controller methods.
o An object that holds validation errors after binding request data to a model.
o Use BindingResult in controller method. If it has errors, return the form view with
error messages.
o JSP tags provided by Spring to bind form inputs to model attributes easily. (e.g.,
<form:input>, <form:errors>)
o An attribute added to the model and used to populate form fields or display data. It’s
also annotated using @ModelAttribute.
o A method annotated with @InitBinder that customizes data binding and format
conversions (like date formats).
o @InitBinder
o }
22. How do you implement common logic for controllers in Spring MVC?
o It follows MVC principles, supports loose coupling, integrates easily with view
technologies, and provides extensive features for form handling, validation,
exception handling, and REST API support.