Controllers Summary
One of Spring MVC’s major strengths is its rich collection of Controlleroptions. From the very
simple (Controllerinterface) to the complex (AbstractWizardFormController), Spring MVC
has a deep controller hierarchy that is extensible and configurable.
The major design theme for these classes is best summed up with the Open-Closed
Principle, which states that classes should be open for extension but closed for modification.
Many of these controllers lock their behavior down with methods marked as final, but provide
useful extension points for subclasses.
Table 6-5 summarizes the different controller options.
Table 6-5.Controller Options
Name Description
Controller Unifying interface, with no work flow defined.
AbstractController Perfect for all read-only request handlers and has many useful
features.
SimpleFormController Provides a form handling work flow, including validation.
AbstractWizardFormController Splits a long form across multiple pages; includes validation
support.
MultiActionController Handles multiple URIs with different methods inside the
controller itself.
ThrowawayController Non-singleton controller; implements the Command pattern;
unaware of the Servlet API.
ValidatableThrowawayController Like the ThrowawayController, but aware of data binding errors.
UrlFilenameViewController Hides view-only resources behind application URIs; parses the
URI itself.
ParameterizableViewController Hides view-only resources behind the application URI by read a
configuration parameter.
■NoteThere are often many intermediate subclasses between the Controllerclasses mentioned in the
above table, so look for other options when you require specific overridable behavior.
HandlerInterceptors provide filter-like abilities to wrap requests and control the process-
ing pipeline. They are able to bypass Controllers, interject common objects into the model
for views, or even clean up resources after the request is handled. Interceptors are bound to
HandlerMappings, which in turn create a HandlerChainmade up of all the interceptors and a
single Controller.
The SimpleFormControllerand any Controllerthat subclasses BaseCommandController
will create command objects to encapsulate the form fields from the request. With the help of
PropertyEditors, the properties of the command objects may be of any type (Strings,ints,
java.util.Date, and so on). The ServletRequestDataBinderis responsible for performing the
actual binding of request parameters to command objects.
CHAPTER 6 ■THE CONTROLLER MENAGERIE 199