Spring MVC is a way of using the Model-View-Controller architecture in Spring. Spring MVC is all about the DispatcherServlet, which acts as a FrontController. DispatcherServlet handles/dispatches all the requests to handlers (Controllers). The view resolvers identify which views to display. Handlers mainly are based on @Controller and @RequestMapping annotations. Using @Controller you can create Restservices as well.
A key design principle in Spring Web MVC and in Spring in general is the “Open for extension, closed for modification” principle.
Some methods in the core classes of Spring Web MVC are marked final. As a developer you cannot override these methods to supply your own behavior. This has not been done arbitrarily, but specifically with this principle in mind.
Below is the request and response processing flow of the DispatcherServlet.
Features of Spring MVC
1) Role Separation
Every role like controller, validator, command object, form object, model object, DispatcherServlet, handler mapping, view resolver, and so on — can be fulfilled by a specialized object
2) Powerful and straightforward configurations
Configurations in Spring MVC are very easy and can reference objects across contexts from controllers to services to DAO layers.
3) Adaptability, non-intrusiveness, and flexibility
A controllers can be defined using its method signature for a given scenario using any of the param annotations like @RequestParam, @RequestHeader, @PathVariable
4) Code Resuablity
Business objects can be used either as command or form objects, avoiding the need of duplicating the code for business logic.
5) Customizable binding and validation
Type mismatches as application-level validation errors that keep the offending value, localized date and number binding, and so on instead of String-only form objects with manual parsing and conversion to business objects.
6) Customizable handler mapping and view resolution
Handler mapping and view resolution strategies range from simple URL-based configuration, to sophisticated, purpose-built resolution strategies. Spring is more flexible than web MVC frameworks that mandate a particular technique.
7) Customizable locale and theme resolution
Support for JSPs with or without Spring tag library, support for JSTL, support for Velocity without the need for extra bridges, and so on.
Spring MVC Tutorial
We have created the customized Spring MVC tutorial, which will help you in understanding the Spring MVC concepts and give you a start in Spring MVC development.
Starting with Simple examples
Interceptors and Controllers
- Spring MVC XML view Resolver
- Spring MVC JSP view Resolver
- Spring MVC ResourceBundleViewResolver
- Configure multiple View Resolvers together
- Spring MVC Redirect View examples
- Spring MVC Attributes
- Spring MVC Session Attributes
- Spring MVC Model Attributes
- Spring MVC Flash Attributes
- Spring MVC Form Handling
- Spring MVC Checkbox
- Spring MVC select tag
- Spring MVC password tag
- Spring MVC Error tag
- Spring MVC Input Tag
- Spring MVC label Tag
- Spring MVC Radio Button
- Spring MVC text area
- Spring MVC hidden
RequestParam and PathVariable
JSON AJAX and XML
- Spring MVC JSON Request example
- Spring MVC JSON Response example
- Spring MVC XML Response example
- Spring MVC Ajax handling using JQuery