类 HandlerMethod
- java.lang.Object
- org.springframework.web.method.HandlerMethod
public class HandlerMethod extends Object
Encapsulates information about a handler method consisting of a method and a bean. Provides convenient access to method parameters, the method return value, method annotations, etc.The class may be created with a bean instance or with a bean name (e.g. lazy-init bean, prototype bean). Use
createWithResolvedBean()to obtain aHandlerMethodinstance with a bean instance resolved through the associatedBeanFactory.- 从以下版本开始:
- 3.1
- 作者:
- Arjen Poutsma, Rossen Stoyanchev, Juergen Hoeller, Sam Brannen
嵌套类概要
嵌套类 修饰符和类型 类 说明 protected classHandlerMethod.HandlerMethodParameterA MethodParameter with HandlerMethod-specific behavior.
构造器概要
构造器 限定符 构造器 说明 HandlerMethod(Object bean, Method method)Create an instance from a bean instance and a method.HandlerMethod(Object bean, String methodName, Class<?>... parameterTypes)Create an instance from a bean instance, method name, and parameter types.HandlerMethod(String beanName, BeanFactory beanFactory, Method method)Create an instance from a bean name, a method, and aBeanFactory.protectedHandlerMethod(HandlerMethod handlerMethod)Copy constructor for use in subclasses.
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 protected voidassertTargetBean(Method method, Object targetBean, Object[] args)Assert that the target bean class is an instance of the class where the given method is declared.HandlerMethodcreateWithResolvedBean()If the provided instance contains a bean name rather than an object instance, the bean name is resolved before aHandlerMethodis created and returned.booleanequals(Object other)protected static ObjectfindProvidedArgument(MethodParameter parameter, Object... providedArgs)protected static StringformatArgumentError(MethodParameter param, String message)protected StringformatInvokeError(String text, Object[] args)ObjectgetBean()Return the bean for this handler method.Class<?>getBeanType()This method returns the type of the handler for this handler method.protected MethodgetBridgedMethod()If the bean method is a bridge method, this method returns the bridged (user-defined) method.MethodgetMethod()Return the method for this handler method.<A extends Annotation>
AgetMethodAnnotation(Class<A> annotationType)Return a single annotation on the underlying method traversing its super methods if no annotation can be found on the given method itself.MethodParameter[]getMethodParameters()Return the method parameters for this handler method.HandlerMethodgetResolvedFromHandlerMethod()Return the HandlerMethod from which this HandlerMethod instance was resolved viacreateWithResolvedBean().protected HttpStatusgetResponseStatus()Return the specified response status, if any.protected StringgetResponseStatusReason()Return the associated response status reason, if any.MethodParametergetReturnType()Return the HandlerMethod return type.MethodParametergetReturnValueType(Object returnValue)Return the actual return value type.StringgetShortLogMessage()Return a short representation of this handler method for log message purposes.inthashCode()<A extends Annotation>
booleanhasMethodAnnotation(Class<A> annotationType)Return whether the parameter is declared with the given annotation type.booleanisVoid()Returntrueif the method return type is void,falseotherwise.StringtoString()
构造器详细资料
HandlerMethod
public HandlerMethod(Object bean, Method method)
Create an instance from a bean instance and a method.
HandlerMethod
public HandlerMethod(Object bean, String methodName, Class<?>... parameterTypes) throws NoSuchMethodException
Create an instance from a bean instance, method name, and parameter types.- 抛出:
NoSuchMethodException- when the method cannot be found
HandlerMethod
public HandlerMethod(String beanName, BeanFactory beanFactory, Method method)
Create an instance from a bean name, a method, and aBeanFactory. The methodcreateWithResolvedBean()may be used later to re-create theHandlerMethodwith an initialized bean.
HandlerMethod
protected HandlerMethod(HandlerMethod handlerMethod)
Copy constructor for use in subclasses.
方法详细资料
getBeanType
public Class<?> getBeanType()
This method returns the type of the handler for this handler method.Note that if the bean type is a CGLIB-generated class, the original user-defined class is returned.
getBridgedMethod
protected Method getBridgedMethod()
If the bean method is a bridge method, this method returns the bridged (user-defined) method. Otherwise it returns the same method asgetMethod().
getMethodParameters
public MethodParameter[] getMethodParameters()
Return the method parameters for this handler method.
getResponseStatus
@Nullable protected HttpStatus getResponseStatus()
Return the specified response status, if any.- 从以下版本开始:
- 4.3.8
- 另请参阅:
ResponseStatus.code()
getResponseStatusReason
@Nullable protected String getResponseStatusReason()
Return the associated response status reason, if any.- 从以下版本开始:
- 4.3.8
- 另请参阅:
ResponseStatus.reason()
getReturnType
public MethodParameter getReturnType()
Return the HandlerMethod return type.
getReturnValueType
public MethodParameter getReturnValueType(@Nullable Object returnValue)
Return the actual return value type.
isVoid
public boolean isVoid()
Returntrueif the method return type is void,falseotherwise.
getMethodAnnotation
@Nullable public <A extends Annotation> A getMethodAnnotation(Class<A> annotationType)
Return a single annotation on the underlying method traversing its super methods if no annotation can be found on the given method itself.Also supports merged composed annotations with attribute overrides as of Spring Framework 4.2.2.
- 参数:
annotationType- the type of annotation to introspect the method for- 返回:
- the annotation, or
nullif none found - 另请参阅:
AnnotatedElementUtils.findMergedAnnotation(java.lang.reflect.AnnotatedElement, java.lang.Class<A>)
hasMethodAnnotation
public <A extends Annotation> boolean hasMethodAnnotation(Class<A> annotationType)
Return whether the parameter is declared with the given annotation type.- 参数:
annotationType- the annotation type to look for- 从以下版本开始:
- 4.3
- 另请参阅:
AnnotatedElementUtils.hasAnnotation(java.lang.reflect.AnnotatedElement, java.lang.Class<? extends java.lang.annotation.Annotation>)
getResolvedFromHandlerMethod
@Nullable public HandlerMethod getResolvedFromHandlerMethod()
Return the HandlerMethod from which this HandlerMethod instance was resolved viacreateWithResolvedBean().
createWithResolvedBean
public HandlerMethod createWithResolvedBean()
If the provided instance contains a bean name rather than an object instance, the bean name is resolved before aHandlerMethodis created and returned.
getShortLogMessage
public String getShortLogMessage()
Return a short representation of this handler method for log message purposes.- 从以下版本开始:
- 4.3
findProvidedArgument
@Nullable protected static Object findProvidedArgument(MethodParameter parameter, @Nullable Object... providedArgs)
formatArgumentError
protected static String formatArgumentError(MethodParameter param, String message)
assertTargetBean
protected void assertTargetBean(Method method, Object targetBean, Object[] args)
Assert that the target bean class is an instance of the class where the given method is declared. In some cases the actual controller instance at request- processing time may be a JDK dynamic proxy (lazy initialization, prototype beans, and others).@Controller's that require proxying should prefer class-based proxy mechanisms.
formatInvokeError
protected String formatInvokeError(String text, Object[] args)