类 RequestContextHolder
- java.lang.Object
- org.springframework.web.context.request.RequestContextHolder
public abstract class RequestContextHolder extends Object
Holder class to expose the web request in the form of a thread-boundRequestAttributesobject. The request will be inherited by any child threads spawned by the current thread if theinheritableflag is set totrue.Use
RequestContextListenerorRequestContextFilterto expose the current web request. Note thatDispatcherServletandDispatcherPortletalready expose the current request by default.- 从以下版本开始:
- 2.0
- 作者:
- Juergen Hoeller, Rod Johnson
- 另请参阅:
RequestContextListener,RequestContextFilter,DispatcherServlet,DispatcherPortlet
构造器概要
构造器 构造器 说明 RequestContextHolder()
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static RequestAttributescurrentRequestAttributes()Return the RequestAttributes currently bound to the thread.static RequestAttributesgetRequestAttributes()Return the RequestAttributes currently bound to the thread.static voidresetRequestAttributes()Reset the RequestAttributes for the current thread.static voidsetRequestAttributes(RequestAttributes attributes)Bind the given RequestAttributes to the current thread, not exposing it as inheritable for child threads.static voidsetRequestAttributes(RequestAttributes attributes, boolean inheritable)Bind the given RequestAttributes to the current thread.
构造器详细资料
RequestContextHolder
public RequestContextHolder()
方法详细资料
resetRequestAttributes
public static void resetRequestAttributes()
Reset the RequestAttributes for the current thread.
setRequestAttributes
public static void setRequestAttributes(RequestAttributes attributes)
Bind the given RequestAttributes to the current thread, not exposing it as inheritable for child threads.- 参数:
attributes- the RequestAttributes to expose- 另请参阅:
setRequestAttributes(RequestAttributes, boolean)
setRequestAttributes
public static void setRequestAttributes(RequestAttributes attributes, boolean inheritable)
Bind the given RequestAttributes to the current thread.- 参数:
attributes- the RequestAttributes to expose, ornullto reset the thread-bound contextinheritable- whether to expose the RequestAttributes as inheritable for child threads (using anInheritableThreadLocal)
getRequestAttributes
public static RequestAttributes getRequestAttributes()
Return the RequestAttributes currently bound to the thread.- 返回:
- the RequestAttributes currently bound to the thread, or
nullif none bound
currentRequestAttributes
public static RequestAttributes currentRequestAttributes() throws IllegalStateException
Return the RequestAttributes currently bound to the thread.Exposes the previously bound RequestAttributes instance, if any. Falls back to the current JSF FacesContext, if any.
- 返回:
- the RequestAttributes currently bound to the thread
- 抛出:
IllegalStateException- if no RequestAttributes object is bound to the current thread- 另请参阅:
setRequestAttributes(org.springframework.web.context.request.RequestAttributes),ServletRequestAttributes,FacesRequestAttributes,FacesContext.getCurrentInstance()