Class WebMvcUtils
java.lang.Object
io.microsphere.spring.webmvc.util.WebMvcUtils
- All Implemented Interfaces:
io.microsphere.util.Utils
Spring Web MVC Utilities Class
- Since:
- 1.0.0
- Author:
- Mercy
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringAny number of these characters are considered delimiters between multiple values in a single init-param String value.The supportedHttpMessageConvertertypes -
Method Summary
Modifier and TypeMethodDescriptionprotected static String[]getClassNames(Class<?>... classes) static Object[]getHandlerMethodArguments(jakarta.servlet.http.HttpServletRequest request, Method method) Gets theHandlerMethodmethod parameterstatic Object[]getHandlerMethodArguments(jakarta.servlet.http.HttpServletRequest request, org.springframework.web.method.HandlerMethod handlerMethod) Gets theHandlerMethodmethod parameterstatic Object[]getHandlerMethodArguments(Method method) Gets theHandlerMethodmethod parameterstatic Object[]getHandlerMethodArguments(org.springframework.web.method.HandlerMethod handlerMethod) Gets theHandlerMethodmethod parameterstatic <T> TgetHandlerMethodRequestBodyArgument(jakarta.servlet.http.HttpServletRequest request, Method method) Gets the@RequestBodymethod parameter from theHttpServletRequestcontextstatic <T> TgetHandlerMethodRequestBodyArgument(jakarta.servlet.http.HttpServletRequest request, org.springframework.web.method.HandlerMethod handlerMethod) Gets the@RequestBodymethod parameter from theHttpServletRequestcontextstatic <T> TGets the@RequestBodymethod parameter from theHttpServletRequestcontextstatic <T> TgetHandlerMethodRequestBodyArgument(org.springframework.web.method.HandlerMethod handlerMethod) Gets the@RequestBodymethod parameter from theHttpServletRequestcontextstatic <T> TgetHandlerMethodReturnValue(jakarta.servlet.http.HttpServletRequest request, Method method) Gets the value returned by theHandlerMethodmethodstatic <T> TgetHandlerMethodReturnValue(jakarta.servlet.http.HttpServletRequest request, org.springframework.web.method.HandlerMethod handlerMethod) Gets the value returned by theHandlerMethodmethodstatic <T> TgetHandlerMethodReturnValue(Method method) Gets the value returned by theHandlerMethodmethodstatic <T> TgetHandlerMethodReturnValue(org.springframework.web.method.HandlerMethod handlerMethod) static jakarta.servlet.http.HttpServletRequestGets the currentHttpServletRequestobjectstatic jakarta.servlet.http.HttpServletRequestgetHttpServletRequest(org.springframework.web.context.request.RequestAttributes requestAttributes) static org.springframework.web.context.WebApplicationContextGets theWebApplicationContextassociated with the current Servlet Request requeststatic org.springframework.web.context.WebApplicationContextgetWebApplicationContext(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.ServletContext servletContext) Get theWebApplicationContextfromHttpServletRequeststatic booleanisControllerAdviceBeanType(Class<?> beanType) Determine whether the Bean Type is present annotated byControllerAdvicestatic booleanisPageRenderRequest(org.springframework.web.servlet.ModelAndView modelAndView) Is page render requeststatic voidsetContextInitializerClassInitParameter(jakarta.servlet.ServletContext servletContext, Class<? extends org.springframework.context.ApplicationContextInitializer>... contextInitializerClasses) Sets the initialized parameter forContext Initializer Classstatic voidsetFrameworkServletContextInitializerClassInitParameter(jakarta.servlet.ServletContext servletContext, Class<? extends org.springframework.context.ApplicationContextInitializer>... contextInitializerClasses) Sets initialized parameter forContext Initializer ClassintoFrameworkServletstatic voidsetGlobalInitializerClassInitParameter(jakarta.servlet.ServletContext servletContext, Class<? extends org.springframework.context.ApplicationContextInitializer>... contextInitializerClasses) Sets the initialized parameter forGlobal Initializer Classstatic voidsetHandlerMethodRequestBodyArgument(jakarta.servlet.http.HttpServletRequest request, Method method, Object requestBodyArgument) Set the@RequestBodymethod parameter inHandlerMethodto theHttpServletRequestcontextstatic voidsetHandlerMethodRequestBodyArgument(Method method, Object requestBodyArgument) Set the@RequestBodymethod parameter inHandlerMethodto theHttpServletRequestcontextstatic voidsetHandlerMethodReturnValue(jakarta.servlet.http.HttpServletRequest request, Method method, Object returnValue) Set the return value of theHandlerMethodto theHttpServletRequestcontextstatic voidsetHandlerMethodReturnValue(Method method, Object returnValue) Set the return value of theHandlerMethodto theHttpServletRequestcontextstatic voidsetInitParameters(jakarta.servlet.ServletContext servletContext, String parameterName, String... parameterValues) SetsServletContext Intialized Parameters
-
Field Details
-
SUPPORTED_CONVERTER_TYPES
public static final Set<Class<? extends org.springframework.http.converter.HttpMessageConverter<?>>> SUPPORTED_CONVERTER_TYPESThe supportedHttpMessageConvertertypes -
INIT_PARAM_DELIMITERS
Any number of these characters are considered delimiters between multiple values in a single init-param String value.- See Also:
-
ContextLoader.INIT_PARAM_DELIMITERS- Constant Field Values
-
-
Method Details
-
getHttpServletRequest
@Nullable public static jakarta.servlet.http.HttpServletRequest getHttpServletRequest() throws IllegalStateExceptionGets the currentHttpServletRequestobjectBy default,
HttpServletRequestis initialized inRequestContextFilter,HttpServletRequestfrom the Servlet HTTP request threadThreadLocalis obtained fromInheritableThreadLocaland can be obtained in the child thread.- Returns:
nullreturns the currentHttpServletRequestobject.- Throws:
IllegalStateException
-
getHttpServletRequest
@Nullable public static jakarta.servlet.http.HttpServletRequest getHttpServletRequest(org.springframework.web.context.request.RequestAttributes requestAttributes) -
getWebApplicationContext
@Nonnull public static org.springframework.web.context.WebApplicationContext getWebApplicationContext() throws IllegalStateExceptionGets theWebApplicationContextassociated with the current Servlet Request request- Returns:
- Current Servlet Request associated with
WebApplicationContext - Throws:
IllegalStateException- In a non-Web scenario, an exception is thrown
-
getWebApplicationContext
@Nullable public static org.springframework.web.context.WebApplicationContext getWebApplicationContext(jakarta.servlet.http.HttpServletRequest request, @Nullable jakarta.servlet.ServletContext servletContext) Get theWebApplicationContextfromHttpServletRequest- Parameters:
request-HttpServletRequestservletContext-ServletContext- Returns:
WebApplicationContext- Throws:
IllegalStateException- if no servlet-specific context has been found- See Also:
-
RequestContextUtils#getWebApplicationContext(HttpServletRequest)RequestContextUtils.findWebApplicationContext(HttpServletRequest, ServletContext)DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE
-
setHandlerMethodRequestBodyArgument
Set the@RequestBodymethod parameter inHandlerMethodto theHttpServletRequestcontext- Parameters:
method- HandlerMethodrequestBodyArgument-@RequestBodyThe method parameters
-
setHandlerMethodRequestBodyArgument
public static void setHandlerMethodRequestBodyArgument(jakarta.servlet.http.HttpServletRequest request, Method method, Object requestBodyArgument) Set the@RequestBodymethod parameter inHandlerMethodto theHttpServletRequestcontext- Parameters:
request-HttpServletRequestmethod- HandlerMethodrequestBodyArgument-@RequestBodyThe method parameters
-
setHandlerMethodReturnValue
Set the return value of theHandlerMethodto theHttpServletRequestcontext- Parameters:
method- HandlerMethodreturnValue- The return value
-
setHandlerMethodReturnValue
public static void setHandlerMethodReturnValue(jakarta.servlet.http.HttpServletRequest request, Method method, Object returnValue) Set the return value of theHandlerMethodto theHttpServletRequestcontext- Parameters:
request-HttpServletRequestmethod- HandlerMethodreturnValue- The return value
-
getHandlerMethodRequestBodyArgument
@Nullable public static <T> T getHandlerMethodRequestBodyArgument(org.springframework.web.method.HandlerMethod handlerMethod) Gets the@RequestBodymethod parameter from theHttpServletRequestcontext- Type Parameters:
T-@RequestBodyMethod parameter Types- Parameters:
handlerMethod-HandlerMethod- Returns:
@RequestBodyMethod parameters if present, otherwise,null
-
getHandlerMethodRequestBodyArgument
@Nullable public static <T> T getHandlerMethodRequestBodyArgument(jakarta.servlet.http.HttpServletRequest request, org.springframework.web.method.HandlerMethod handlerMethod) Gets the@RequestBodymethod parameter from theHttpServletRequestcontext- Type Parameters:
T-@RequestBodyMethod parameter Types- Parameters:
request-HttpServletRequesthandlerMethod-HandlerMethod- Returns:
@RequestBodyMethod parameters if present, otherwise,null
-
getHandlerMethodRequestBodyArgument
Gets the@RequestBodymethod parameter from theHttpServletRequestcontext- Type Parameters:
T-@RequestBodyMethod parameter Types- Parameters:
method- HandlerMethod- Returns:
@RequestBodymethod parameter if present, otherwisenull
-
getHandlerMethodRequestBodyArgument
@Nonnull public static <T> T getHandlerMethodRequestBodyArgument(jakarta.servlet.http.HttpServletRequest request, Method method) Gets the@RequestBodymethod parameter from theHttpServletRequestcontext- Type Parameters:
T-@RequestBodyMethod parameter Types- Parameters:
request-HttpServletRequestmethod- HandlerMethod- Returns:
@RequestBodymethod parameter if present, otherwisenull
-
getHandlerMethodArguments
@Nonnull public static Object[] getHandlerMethodArguments(org.springframework.web.method.HandlerMethod handlerMethod) Gets theHandlerMethodmethod parameter- Parameters:
handlerMethod-HandlerMethod- Returns:
- non-null
-
getHandlerMethodArguments
@Nonnull public static Object[] getHandlerMethodArguments(jakarta.servlet.http.HttpServletRequest request, org.springframework.web.method.HandlerMethod handlerMethod) Gets theHandlerMethodmethod parameter- Parameters:
request-HttpServletRequesthandlerMethod-HandlerMethod- Returns:
- non-null
-
getHandlerMethodArguments
Gets theHandlerMethodmethod parameter- Parameters:
method-HandlerMethod- Returns:
- non-null
-
getHandlerMethodArguments
@Nonnull public static Object[] getHandlerMethodArguments(jakarta.servlet.http.HttpServletRequest request, Method method) Gets theHandlerMethodmethod parameter- Parameters:
request-HttpServletRequestmethod-Method- Returns:
- non-null
-
getHandlerMethodReturnValue
@Nullable public static <T> T getHandlerMethodReturnValue(org.springframework.web.method.HandlerMethod handlerMethod) -
getHandlerMethodReturnValue
@Nullable public static <T> T getHandlerMethodReturnValue(jakarta.servlet.http.HttpServletRequest request, org.springframework.web.method.HandlerMethod handlerMethod) Gets the value returned by theHandlerMethodmethod- Type Parameters:
T- Method return value type- Parameters:
request-HttpServletRequesthandlerMethod-HandlerMethod- Returns:
HandlerMethodMethod return value
-
getHandlerMethodReturnValue
Gets the value returned by theHandlerMethodmethod- Type Parameters:
T- Method return value type- Parameters:
method-Method- Returns:
HandlerMethodMethod return value
-
getHandlerMethodReturnValue
@Nullable public static <T> T getHandlerMethodReturnValue(jakarta.servlet.http.HttpServletRequest request, Method method) Gets the value returned by theHandlerMethodmethod- Type Parameters:
T- Method return value type- Parameters:
request-HttpServletRequestmethod-Method- Returns:
HandlerMethodMethod return value
-
isControllerAdviceBeanType
Determine whether the Bean Type is present annotated byControllerAdvice- Parameters:
beanType- Bean Type- Returns:
- If
ControllerAdvicebean type is present , returntrue, orfalse.
-
setInitParameters
public static void setInitParameters(jakarta.servlet.ServletContext servletContext, String parameterName, String... parameterValues) SetsServletContext Intialized Parameters- Parameters:
servletContext-ServletContextparameterName- the name of init parameterparameterValues- the values of init parameters
-
setGlobalInitializerClassInitParameter
public static void setGlobalInitializerClassInitParameter(jakarta.servlet.ServletContext servletContext, Class<? extends org.springframework.context.ApplicationContextInitializer>... contextInitializerClasses) Sets the initialized parameter forGlobal Initializer Class- Parameters:
servletContext-ServletContextcontextInitializerClasses- the classes ofApplicationContextInitializer- See Also:
-
ContextLoader.GLOBAL_INITIALIZER_CLASSES_PARAM
-
setContextInitializerClassInitParameter
public static void setContextInitializerClassInitParameter(jakarta.servlet.ServletContext servletContext, Class<? extends org.springframework.context.ApplicationContextInitializer>... contextInitializerClasses) Sets the initialized parameter forContext Initializer Class- Parameters:
servletContext-ServletContextcontextInitializerClasses- the classes ofApplicationContextInitializer- See Also:
-
ContextLoader.CONTEXT_INITIALIZER_CLASSES_PARAM
-
setFrameworkServletContextInitializerClassInitParameter
public static void setFrameworkServletContextInitializerClassInitParameter(jakarta.servlet.ServletContext servletContext, Class<? extends org.springframework.context.ApplicationContextInitializer>... contextInitializerClasses) Sets initialized parameter forContext Initializer ClassintoFrameworkServlet- Parameters:
servletContext-ServletContextcontextInitializerClasses- the classes ofApplicationContextInitializer- See Also:
-
FrameworkServlet.applyInitializers(ConfigurableApplicationContext)
-
isPageRenderRequest
public static boolean isPageRenderRequest(org.springframework.web.servlet.ModelAndView modelAndView) Is page render request- Parameters:
modelAndView-ModelAndView- Returns:
- If current request is for page render , return
true, orfalse.
-
getClassNames
-