类 MultiActionController
- java.lang.Object
- org.springframework.context.support.ApplicationObjectSupport
- org.springframework.web.context.support.WebApplicationObjectSupport
- org.springframework.web.servlet.support.WebContentGenerator
- org.springframework.web.servlet.mvc.AbstractController
- org.springframework.web.servlet.mvc.multiaction.MultiActionController
@Deprecated public class MultiActionController extends AbstractController implements LastModified
已过时。as of 4.3, in favor of annotation-driven handler methodsController
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 formpublic (ModelAndView | Map | String | void) actionName(HttpServletRequest request, HttpServletResponse response, [,HttpSession] [,AnyObject]);
A Map return value indicates a model that is supposed to be passed to a default view (determined through aRequestToViewNameTranslator
). A String return value indicates the name of a view to be rendered without a specific model.May take a third parameter (of type
HttpSession
) in which an existing session will be required, or a third parameter of an arbitrary class that gets treated as the command (that is, 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 configuredRequestToViewNameTranslator
will be used to determine the view name.When returning
void
a return value ofnull
is assumed meaning that the handler method is responsible for writing the response directly to the suppliedHttpServletResponse
.This model allows for rapid coding, but loses the advantage of compile-time checking. It is similar to a Struts
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 eachMultiActionController
.The default
MethodNameResolver
isInternalPathMethodNameResolver
; further included strategies arePropertiesMethodNameResolver
andParameterMethodNameResolver
.Subclasses can implement custom exception handler methods with names such as:
public ModelAndView anyMeaningfulName(HttpServletRequest request, HttpServletResponse response, ExceptionClass exception);
The third parameter can be any subclass orException
orRuntimeException
.There can also be an optional
xxxLastModified
method for handlers, of signature:public long anyMeaningfulNameLastModified(HttpServletRequest request)
If such a method is present, it will be invoked. Default return fromgetLastModified
is -1, meaning that the content must always be regenerated.Note that all handler methods need to be public and that method overloading is not allowed.
See also the description of the workflow performed by
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 ofValidators
and the subsequent evaluation of binding/validation errors.- 作者:
- Rod Johnson, Juergen Hoeller, Colin Sampaleanu, Rob Harrop, Sam Brannen
- 另请参阅:
MethodNameResolver
,InternalPathMethodNameResolver
,PropertiesMethodNameResolver
,ParameterMethodNameResolver
,LastModified.getLastModified(javax.servlet.http.HttpServletRequest)
,ServletRequestDataBinder
字段概要
字段 修饰符和类型 字段 说明 static String
DEFAULT_COMMAND_NAME
已过时。Default command name used for binding command objects: "command"static String
LAST_MODIFIED_METHOD_SUFFIX
已过时。Suffix for last-modified methodsstatic String
PAGE_NOT_FOUND_LOG_CATEGORY
已过时。Log category to use when no mapped handler is found for a request.protected static Log
pageNotFoundLogger
已过时。Additional logger to use when no mapped handler is found for a request.从类继承的字段 org.springframework.web.servlet.support.WebContentGenerator
HEADER_CACHE_CONTROL, METHOD_GET, METHOD_HEAD, METHOD_POST
从类继承的字段 org.springframework.context.support.ApplicationObjectSupport
logger
构造器概要
构造器 构造器 说明 MultiActionController()
已过时。Constructor forMultiActionController
that looks for handler methods in the present subclass.MultiActionController(Object delegate)
已过时。Constructor forMultiActionController
that looks for handler methods in delegate, rather than a subclass of this class.
方法概要
所有方法 实例方法 具体方法 已过时的方法 修饰符和类型 方法 说明 protected void
bind(HttpServletRequest request, Object command)
已过时。Bind request parameters onto the given command beanprotected ServletRequestDataBinder
createBinder(HttpServletRequest request, Object command)
已过时。Create a new binder instance for the given command and request.protected String
getCommandName(Object command)
已过时。Return the command name to use for the given command object.protected Method
getExceptionHandler(Throwable exception)
已过时。Determine the exception handler method for the given exception.long
getLastModified(HttpServletRequest request)
已过时。Try to find an XXXXLastModified method, where XXXX is the name of a handler.MethodNameResolver
getMethodNameResolver()
已过时。Return the MethodNameResolver used by this class.Validator[]
getValidators()
已过时。Return the Validators for this controller.WebBindingInitializer
getWebBindingInitializer()
已过时。Return the WebBindingInitializer (if any) which will apply pre-configured configuration to every DataBinder that this controller uses.protected ModelAndView
handleNoSuchRequestHandlingMethod(NoSuchRequestHandlingMethodException ex, HttpServletRequest request, HttpServletResponse response)
已过时。Handle the case where no request handler method was found.protected ModelAndView
handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
已过时。Determine a handler method and invoke it.protected void
initBinder(HttpServletRequest request, ServletRequestDataBinder binder)
已过时。Initialize the given binder instance, for example with custom editors.protected ModelAndView
invokeNamedMethod(String methodName, HttpServletRequest request, HttpServletResponse response)
已过时。Invokes the named method.protected Object
newCommandObject(Class<?> clazz)
已过时。Create a new command object of the given class.void
setDelegate(Object delegate)
已过时。Set the delegate used by this class; the default isthis
, assuming that handler methods have been added by a subclass.void
setMethodNameResolver(MethodNameResolver methodNameResolver)
已过时。Set the method name resolver that this class should use.void
setValidators(Validator[] validators)
已过时。Set theValidators
for this controller.void
setWebBindingInitializer(WebBindingInitializer webBindingInitializer)
已过时。Specify a WebBindingInitializer which will apply pre-configured configuration to every DataBinder that this controller uses.从类继承的方法 org.springframework.web.servlet.mvc.AbstractController
handleRequest, isSynchronizeOnSession, setSynchronizeOnSession
从类继承的方法 org.springframework.web.servlet.support.WebContentGenerator
applyCacheControl, applyCacheSeconds, applyCacheSeconds, cacheForSeconds, cacheForSeconds, checkAndPrepare, checkAndPrepare, checkRequest, getAllowHeader, getCacheControl, getCacheSeconds, getSupportedMethods, getVaryByRequestHeaders, isAlwaysMustRevalidate, isRequireSession, isUseCacheControlHeader, isUseCacheControlNoStore, isUseExpiresHeader, prepareResponse, preventCaching, setAlwaysMustRevalidate, setCacheControl, setCacheSeconds, setRequireSession, setSupportedMethods, setUseCacheControlHeader, setUseCacheControlNoStore, setUseExpiresHeader, setVaryByRequestHeaders
从类继承的方法 org.springframework.web.context.support.WebApplicationObjectSupport
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext
从类继承的方法 org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, initApplicationContext, requiredContextClass, setApplicationContext
字段详细资料
LAST_MODIFIED_METHOD_SUFFIX
public static final String LAST_MODIFIED_METHOD_SUFFIX
已过时。Suffix for last-modified methods- 另请参阅:
- 常量字段值
DEFAULT_COMMAND_NAME
public static final String DEFAULT_COMMAND_NAME
已过时。Default command name used for binding command objects: "command"- 另请参阅:
- 常量字段值
PAGE_NOT_FOUND_LOG_CATEGORY
public static final String PAGE_NOT_FOUND_LOG_CATEGORY
已过时。Log category to use when no mapped handler is found for a request.- 另请参阅:
pageNotFoundLogger
, 常量字段值
pageNotFoundLogger
protected static final Log pageNotFoundLogger
已过时。Additional logger to use when no mapped handler is found for a request.
构造器详细资料
MultiActionController
public MultiActionController()
已过时。Constructor forMultiActionController
that looks for handler methods in the present subclass.
MultiActionController
public MultiActionController(Object delegate)
已过时。Constructor forMultiActionController
that looks for handler methods in delegate, rather than a subclass of this class.- 参数:
delegate
- handler object. This does not need to implement any particular interface, as everything is done using reflection.
方法详细资料
setDelegate
public final void setDelegate(Object delegate)
已过时。Set the delegate used by this class; the default isthis
, assuming that handler methods have been added by a subclass.This method does not get invoked once the class is configured.
- 参数:
delegate
- an object containing handler methods- 抛出:
IllegalStateException
- if no handler methods are found
setMethodNameResolver
public final void setMethodNameResolver(MethodNameResolver methodNameResolver)
已过时。Set the method name resolver that this class should use.Allows parameterization of handler method mappings.
getMethodNameResolver
public final MethodNameResolver getMethodNameResolver()
已过时。Return the MethodNameResolver used by this class.
setValidators
public final void setValidators(Validator[] validators)
已过时。Set theValidators
for this controller.The
Validators
must support the specified command class.
getValidators
public final Validator[] getValidators()
已过时。Return the Validators for this controller.
setWebBindingInitializer
public final void setWebBindingInitializer(WebBindingInitializer webBindingInitializer)
已过时。Specify a WebBindingInitializer which will apply pre-configured configuration to every DataBinder that this controller uses.Allows for factoring out the entire binder configuration to separate objects, as an alternative to
initBinder(javax.servlet.http.HttpServletRequest, org.springframework.web.bind.ServletRequestDataBinder)
.
getWebBindingInitializer
public final WebBindingInitializer getWebBindingInitializer()
已过时。Return the WebBindingInitializer (if any) which will apply pre-configured configuration to every DataBinder that this controller uses.
getLastModified
public long getLastModified(HttpServletRequest request)
已过时。Try to find an XXXXLastModified method, where XXXX is the name of a handler. Return -1 if there's no such handler, indicating that content must be updated.- 指定者:
getLastModified
在接口中LastModified
- 参数:
request
- current HTTP request- 返回:
- the time the underlying resource was last modified, or -1 meaning that the content must always be regenerated
- 另请参阅:
LastModified.getLastModified(HttpServletRequest)
handleRequestInternal
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception
已过时。Determine a handler method and invoke it.- 指定者:
handleRequestInternal
在类中AbstractController
- 抛出:
Exception
- 另请参阅:
MethodNameResolver.getHandlerMethodName(javax.servlet.http.HttpServletRequest)
,invokeNamedMethod(java.lang.String, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
,handleNoSuchRequestHandlingMethod(org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
handleNoSuchRequestHandlingMethod
protected ModelAndView handleNoSuchRequestHandlingMethod(NoSuchRequestHandlingMethodException ex, HttpServletRequest request, HttpServletResponse response) throws Exception
已过时。Handle the case where no request handler method was found.The default implementation logs a warning and sends an HTTP 404 error. Alternatively, a fallback view could be chosen, or the NoSuchRequestHandlingMethodException could be rethrown as-is.
- 参数:
ex
- the NoSuchRequestHandlingMethodException to be handledrequest
- current HTTP requestresponse
- current HTTP response- 返回:
- a ModelAndView to render, or
null
if handled directly - 抛出:
Exception
- an Exception that should be thrown as result of the servlet request
invokeNamedMethod
protected final ModelAndView invokeNamedMethod(String methodName, HttpServletRequest request, HttpServletResponse response) throws Exception
已过时。Invokes the named method.Uses a custom exception handler if possible; otherwise, throw an unchecked exception; wrap a checked exception or Throwable.
- 抛出:
Exception
newCommandObject
protected Object newCommandObject(Class<?> clazz) throws Exception
已过时。Create a new command object of the given class.This implementation uses
BeanUtils.instantiateClass
, so commands need to have public no-arg constructors. Subclasses can override this implementation if desired.- 抛出:
Exception
- if the command object could not be instantiated- 另请参阅:
BeanUtils.instantiateClass(Class)
bind
protected void bind(HttpServletRequest request, Object command) throws Exception
已过时。Bind request parameters onto the given command bean- 参数:
request
- request from which parameters will be boundcommand
- command object, that must be a JavaBean- 抛出:
Exception
- in case of invalid state or arguments
createBinder
protected ServletRequestDataBinder createBinder(HttpServletRequest request, Object command) throws Exception
已过时。Create a new binder instance for the given command and request.Called by
bind
. Can be overridden to plug in custom ServletRequestDataBinder subclasses.The default implementation creates a standard ServletRequestDataBinder, and invokes
initBinder
. Note thatinitBinder
will not be invoked if you override this method!- 参数:
request
- current HTTP requestcommand
- the command to bind onto- 返回:
- the new binder instance
- 抛出:
Exception
- in case of invalid state or arguments- 另请参阅:
bind(javax.servlet.http.HttpServletRequest, java.lang.Object)
,initBinder(javax.servlet.http.HttpServletRequest, org.springframework.web.bind.ServletRequestDataBinder)
getCommandName
protected String getCommandName(Object command)
已过时。Return the command name to use for the given command object.Default is "command".
- 参数:
command
- the command object- 返回:
- the command name to use
- 另请参阅:
DEFAULT_COMMAND_NAME
initBinder
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception
已过时。Initialize the given binder instance, for example with custom editors. Called bycreateBinder
.This method allows you to register custom editors for certain fields of your command class. For instance, you will be able to transform Date objects into a String pattern and back, in order to allow your JavaBeans to have Date properties and still be able to set and display them in an HTML interface.
The default implementation is empty.
Note: the command object is not directly passed to this method, but it's available via
DataBinder.getTarget()
- 参数:
request
- current HTTP requestbinder
- new binder instance- 抛出:
Exception
- in case of invalid state or arguments- 另请参阅:
createBinder(javax.servlet.http.HttpServletRequest, java.lang.Object)
,DataBinder.registerCustomEditor(java.lang.Class<?>, java.beans.PropertyEditor)
,CustomDateEditor
getExceptionHandler
protected Method getExceptionHandler(Throwable exception)
已过时。Determine the exception handler method for the given exception.Can return
null
if not found.- 参数:
exception
- the exception to handle- 返回:
- a handler for the given exception type, or
null