类 AbstractController
- 所有已实现的接口:
cn.taketoday.beans.factory.Aware,cn.taketoday.context.ApplicationContextAware,Controller,HttpRequestHandler
- 直接已知子类:
AbstractUrlViewController,ParameterizableViewController,ServletForwardingController,ServletWrappingController
Workflow
(and that defined by interface):
handleRequest()will be called by the DispatcherHandler- Inspection of supported methods
- If session is required, try to get it
- Set caching headers if needed according to the cacheSeconds property
- Call abstract method
handleRequestInternal()(optionally synchronizing around the call on the HttpSession), which should be implemented by extending classes to provide actual functionality to returnModelAndViewobjects.
Exposed configuration properties
(and those defined by interface):
| name | default | description |
| supportedMethods | GET,POST | comma-separated (CSV) list of methods supported by this controller, such as GET, POST and PUT |
| requireSession | false | whether a session should be required for requests to be able to be handled by this controller. This ensures that derived controller can - without fear of null pointers - call request.getSession() to retrieve a session. If no session can be found while processing the request, a RuntimeException will be thrown |
| cacheSeconds | -1 | indicates the amount of seconds to include in the cache header for the response following on this request. 0 (zero) will include headers for no caching at all, -1 (the default) will not generate any headers and any positive number will generate headers that state the amount indicated as seconds to cache the content |
| synchronizeOnSession | false | whether the call to handleRequestInternal should be
synchronized around the WebSession, to serialize invocations
from the same client. No effect if there is no WebSession.
|
- 从以下版本开始:
- 4.0 2022/2/8 15:47
- 作者:
- Rod Johnson, Juergen Hoeller, Rossen Stoyanchev, Harry Yang
- 另请参阅:
-
字段概要
字段从类继承的字段 cn.taketoday.web.WebContentGenerator
HEADER_CACHE_CONTROL, METHOD_GET, METHOD_HEAD, METHOD_POST从类继承的字段 cn.taketoday.context.support.ApplicationObjectSupport
applicationContext, log, messageSourceAccessor从接口继承的字段 cn.taketoday.web.HttpRequestHandler
NONE_RETURN_VALUE -
构造器概要
构造器构造器说明Create a new AbstractController which supports HTTP methods GET, HEAD and POST by default.AbstractController(boolean restrictDefaultSupportedMethods) Create a new AbstractController. -
方法概要
修饰符和类型方法说明handleRequest(RequestContext request) Process the request and return a result object which the DispatcherHandler will handle.protected abstract ObjecthandleRequestInternal(RequestContext request) Template method.final booleanReturn whether controller execution should be synchronized on the session.final voidsetSynchronizeOnSession(boolean synchronizeOnSession) Set if controller execution should be synchronized on the session, to serialize parallel invocations from the same client.从类继承的方法 cn.taketoday.web.WebContentGenerator
applyCacheControl, applyCacheSeconds, checkRequest, getAllowHeader, getCacheControl, getCacheSeconds, getSupportedMethods, getVaryByRequestHeaders, isRequireSession, prepareResponse, setCacheControl, setCacheSeconds, setRequireSession, setSupportedMethods, setVaryByRequestHeaders从类继承的方法 cn.taketoday.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, initApplicationContext, initApplicationContext, isContextRequired, obtainApplicationContext, requiredContextClass, setApplicationContext, unwrapContext, unwrapFactory
-
字段详细资料
-
synchronizeOnSession
private boolean synchronizeOnSession
-
-
构造器详细资料
-
AbstractController
public AbstractController()Create a new AbstractController which supports HTTP methods GET, HEAD and POST by default. -
AbstractController
public AbstractController(boolean restrictDefaultSupportedMethods) Create a new AbstractController.- 参数:
restrictDefaultSupportedMethods-trueif this controller should support HTTP methods GET, HEAD and POST by default, orfalseif it should be unrestricted
-
-
方法详细资料
-
setSynchronizeOnSession
public final void setSynchronizeOnSession(boolean synchronizeOnSession) Set if controller execution should be synchronized on the session, to serialize parallel invocations from the same client.More specifically, the execution of the
handleRequestInternalmethod will get synchronized if this flag is "true". The best available session mutex will be used for the synchronization; ideally, this will be a mutex exposed by WebSessionMutexListener.The session mutex is guaranteed to be the same object during the entire lifetime of the session, available under the key defined by the
SESSION_MUTEX_ATTRIBUTEconstant. It serves as a safe reference to synchronize on for locking on the current session.In many cases, the WebSession reference itself is a safe mutex as well, since it will always be the same object reference for the same active logical session. However, this is not guaranteed across different servlet containers; the only 100% safe way is a session mutex.
-
isSynchronizeOnSession
public final boolean isSynchronizeOnSession()Return whether controller execution should be synchronized on the session. -
handleRequest
从接口复制的说明:HttpRequestHandlerProcess the request and return a result object which the DispatcherHandler will handle. Anullreturn value is not an error: it indicates that this handler completed request processing itself and that there is therefore no explicit result to handle. aHttpRequestHandler.NONE_RETURN_VALUEindicates that no result to handle byReturnValueHandler- 指定者:
handleRequest在接口中HttpRequestHandler- 参数:
request- Current request context- 返回:
- Result to be handled by
ReturnValueHandler - 抛出:
Throwable- If any exception occurred- 另请参阅:
-
handleRequestInternal
Template method. Subclasses must implement this. The contract is the same as forhandleRequest.
-