Controller implementation that allows multiple request types to be
handled by the same class. Subclasses of this class can handle several
different types of request with methods of the form
(ModelAndView | Map | void) actionName(HttpServletRequest request, HttpServletResponse response);
May take a third parameter HttpSession in which an existing session will be required,
or a third parameter of an arbitrary class that gets treated as command
(i.e. an instance of the class gets created, and request parameters get bound to it)
These methods can throw any kind of exception, but should only let propagate
those that they consider fatal, or which their class or superclass is prepared to
catch by implementing an exception handler.
When returning just a
Map instance view name translation will be used to generate
the view name. The configured
org.springframework.web.servlet.RequestToViewNameTranslator will be used to determine the view name.
When returning void a return value of null is assumed
meaning that the handler method is responsible for writing the response directly to
the supplied
HttpServletResponse .
This model allows for rapid coding, but loses the advantage of compile-time
checking. It is similar to a Struts 1.1 DispatchAction, but more sophisticated.
Also supports delegation to another object.
An implementation of the MethodNameResolver interface defined in this package
should return a method name for a given request, based on any aspect of the request,
such as its URL or an "action" parameter. The actual strategy can be configured
via the "methodNameResolver" bean property, for each MultiActionController.
The default MethodNameResolver is InternalPathMethodNameResolver; further included
strategies are PropertiesMethodNameResolver and ParameterMethodNameResolver.
Subclasses can implement custom exception handler methods with names such as:
ModelAndView anyMeaningfulName(HttpServletRequest request, HttpServletResponse response, ExceptionClass exception);
The third parameter can be any subclass or Exception or RuntimeException.
There can also be an optional lastModified method for handlers, of signature:
long anyMeaningfulNameLastModified(HttpServletRequest request)
If such a method is present, it will be invoked. Default return from getLastModified
is -1, meaning that the content must always be regenerated.
Note that method overloading isn't allowed.
See also the description of the workflow performed by
AbstractController the superclass (in that section of the class
level Javadoc entitled 'workflow').
Note: For maximum data binding flexibility, consider direct usage
of a ServletRequestDataBinder in your controller method, instead of relying
on a declared command argument. This allows for full control over the entire
binder setup and usage, including the invocation of Validators and the
subsequent evaluation of binding/validation errors.
author: Rod Johnson author: Juergen Hoeller author: Colin Sampaleanu author: Rob Harrop See Also: MethodNameResolver See Also: InternalPathMethodNameResolver See Also: PropertiesMethodNameResolver See Also: ParameterMethodNameResolver See Also: org.springframework.web.servlet.mvc.LastModified.getLastModified See Also: org.springframework.web.bind.ServletRequestDataBinder |