类 WebContentInterceptor
- 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.WebContentInterceptor
public class WebContentInterceptor extends WebContentGenerator implements HandlerInterceptor
Handler interceptor that checks the request and prepares the response. Checks for supported methods and a required session, and applies the specifiedCacheControl
builder. See superclass bean properties for configuration options.All the settings supported by this interceptor can also be set on
AbstractController
. This interceptor is mainly intended for applying checks and preparations to a set of controllers mapped by a HandlerMapping.- 从以下版本开始:
- 27.11.2003
- 作者:
- Juergen Hoeller, Brian Clozel
- 另请参阅:
AbstractController
字段概要
从类继承的字段 org.springframework.web.servlet.support.WebContentGenerator
HEADER_CACHE_CONTROL, METHOD_GET, METHOD_HEAD, METHOD_POST
从类继承的字段 org.springframework.context.support.ApplicationObjectSupport
logger
构造器概要
构造器 构造器 说明 WebContentInterceptor()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 void
addCacheMapping(CacheControl cacheControl, String... paths)
Map specific URL paths to a specificCacheControl
.void
afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
This implementation is empty.protected CacheControl
lookupCacheControl(String urlPath)
Look up aCacheControl
instance for the given URL path.protected Integer
lookupCacheSeconds(String urlPath)
Look up a cacheSeconds integer value for the given URL path.void
postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)
This implementation is empty.boolean
preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
Intercept the execution of a handler.void
setAlwaysUseFullPath(boolean alwaysUseFullPath)
Shortcut to same property on underlyingUrlPathHelper
.void
setCacheMappings(Properties cacheMappings)
Map specific URL paths to specific cache seconds.void
setPathMatcher(PathMatcher pathMatcher)
Set the PathMatcher implementation to use for matching URL paths against registered URL patterns, for determining cache mappings.void
setUrlDecode(boolean urlDecode)
Shortcut to same property on underlyingUrlPathHelper
.void
setUrlPathHelper(UrlPathHelper urlPathHelper)
Set the UrlPathHelper to use for resolution of lookup paths.从类继承的方法 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, obtainApplicationContext, requiredContextClass, setApplicationContext
构造器详细资料
WebContentInterceptor
public WebContentInterceptor()
方法详细资料
setAlwaysUseFullPath
public void setAlwaysUseFullPath(boolean alwaysUseFullPath)
Shortcut to same property on underlyingUrlPathHelper
.Only relevant for the "cacheMappings" setting.
setUrlDecode
public void setUrlDecode(boolean urlDecode)
Shortcut to same property on underlyingUrlPathHelper
.Only relevant for the "cacheMappings" setting.
setUrlPathHelper
public void setUrlPathHelper(UrlPathHelper urlPathHelper)
Set the UrlPathHelper to use for resolution of lookup paths.Use this to override the default UrlPathHelper with a custom subclass, or to share common UrlPathHelper settings across multiple HandlerMappings and MethodNameResolvers.
Only relevant for the "cacheMappings" setting.
setCacheMappings
public void setCacheMappings(Properties cacheMappings)
Map specific URL paths to specific cache seconds.Overrides the default cache seconds setting of this interceptor. Can specify "-1" to exclude a URL path from default caching.
Supports direct matches, e.g. a registered "/test" matches "/test", and a various Ant-style pattern matches, e.g. a registered "/t*" matches both "/test" and "/team". For details, see the AntPathMatcher javadoc.
NOTE: Path patterns are not supposed to overlap. If a request matches several mappings, it is effectively undefined which one will apply (due to the lack of key ordering in
java.util.Properties
).- 参数:
cacheMappings
- a mapping between URL paths (as keys) and cache seconds (as values, need to be integer-parsable)- 另请参阅:
WebContentGenerator.setCacheSeconds(int)
,AntPathMatcher
addCacheMapping
public void addCacheMapping(CacheControl cacheControl, String... paths)
Map specific URL paths to a specificCacheControl
.Overrides the default cache seconds setting of this interceptor. Can specify a empty
CacheControl
instance to exclude a URL path from default caching.Supports direct matches, e.g. a registered "/test" matches "/test", and a various Ant-style pattern matches, e.g. a registered "/t*" matches both "/test" and "/team". For details, see the AntPathMatcher javadoc.
NOTE: Path patterns are not supposed to overlap. If a request matches several mappings, it is effectively undefined which one will apply (due to the lack of key ordering in the underlying
java.util.HashMap
).- 参数:
cacheControl
- theCacheControl
to usepaths
- the URL paths that will map to the givenCacheControl
- 从以下版本开始:
- 4.2
- 另请参阅:
WebContentGenerator.setCacheSeconds(int)
,AntPathMatcher
setPathMatcher
public void setPathMatcher(PathMatcher pathMatcher)
Set the PathMatcher implementation to use for matching URL paths against registered URL patterns, for determining cache mappings. Default is AntPathMatcher.
preHandle
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws ServletException
从接口复制的说明:HandlerInterceptor
Intercept the execution of a handler. Called after HandlerMapping determined an appropriate handler object, but before HandlerAdapter invokes the handler.DispatcherServlet processes a handler in an execution chain, consisting of any number of interceptors, with the handler itself at the end. With this method, each interceptor can decide to abort the execution chain, typically sending an HTTP error or writing a custom response.
Note: special considerations apply for asynchronous request processing. For more details see
AsyncHandlerInterceptor
.The default implementation returns
true
.- 指定者:
preHandle
在接口中HandlerInterceptor
- 参数:
request
- current HTTP requestresponse
- current HTTP responsehandler
- chosen handler to execute, for type and/or instance evaluation- 返回:
true
if the execution chain should proceed with the next interceptor or the handler itself. Else, DispatcherServlet assumes that this interceptor has already dealt with the response itself.- 抛出:
ServletException
lookupCacheControl
@Nullable protected CacheControl lookupCacheControl(String urlPath)
Look up aCacheControl
instance for the given URL path.Supports direct matches, e.g. a registered "/test" matches "/test", and various Ant-style pattern matches, e.g. a registered "/t*" matches both "/test" and "/team". For details, see the AntPathMatcher class.
- 参数:
urlPath
- the URL the bean is mapped to- 返回:
- the associated
CacheControl
, ornull
if not found - 另请参阅:
AntPathMatcher
lookupCacheSeconds
@Nullable protected Integer lookupCacheSeconds(String urlPath)
Look up a cacheSeconds integer value for the given URL path.Supports direct matches, e.g. a registered "/test" matches "/test", and various Ant-style pattern matches, e.g. a registered "/t*" matches both "/test" and "/team". For details, see the AntPathMatcher class.
- 参数:
urlPath
- the URL the bean is mapped to- 返回:
- the cacheSeconds integer value, or
null
if not found - 另请参阅:
AntPathMatcher
postHandle
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable ModelAndView modelAndView) throws Exception
This implementation is empty.- 指定者:
postHandle
在接口中HandlerInterceptor
- 参数:
request
- current HTTP requestresponse
- current HTTP responsehandler
- the handler (orHandlerMethod
) that started asynchronous execution, for type and/or instance examinationmodelAndView
- theModelAndView
that the handler returned (can also benull
)- 抛出:
Exception
- in case of errors
afterCompletion
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable Exception ex) throws Exception
This implementation is empty.- 指定者:
afterCompletion
在接口中HandlerInterceptor
- 参数:
request
- current HTTP requestresponse
- current HTTP responsehandler
- the handler (orHandlerMethod
) that started asynchronous execution, for type and/or instance examinationex
- any exception thrown on handler execution, if any; this does not include exceptions that have been handled through an exception resolver- 抛出:
Exception
- in case of errors