1. 简单说明
封装有关由方法和bean组成的处理程序方法的信息。提供对方法参数、方法返回值、方法注释等的方便访问。
可以使用bean实例或bean名称(例如lazy-init bean, prototype bean)创建类。使用createWithResolvedBean() 获取HandlerMethod实例,该实例通过关联的BeanFactory解析的bean实例。
2. 属性与方法
private final Object bean;
@Nullable
private final BeanFactory beanFactory;
private final Class<?> beanType;
private final Method method;
private final Method bridgedMethod;
private final MethodParameter[] parameters;
@Nullable
private HttpStatus responseStatus;
@Nullable
private String responseStatusReason;
@Nullable
private HandlerMethod resolvedFromHandlerMethod;
@Nullable
private volatile List<Annotation[][]> interfaceParameterAnnotations;
private final String description;
如果提供的实例包含bean名称而不是对象实例,则在创建和返回HandlerMethod之前解析bean名称。重新生成HandlerMethod对象,以获得真正的Controller bean。代码如下:
public HandlerMethod createWithResolvedBean() {
Object handler = this.bean;
if (this.bean instanceof String) {
Assert.state(this.beanFactory != null, "Cannot resolve bean name without BeanFactory");
String beanName = (String) this.bean;
handler = this.beanFactory.getBean(beanName);
}
return new HandlerMethod(this, handler);
}
image.png
3. 内部类
3.1 HandlerMethodParameter类
具有HandlerMethod特定行为的MethodParameter。
image.png
3.2 ReturnValueMethodParameter类
HandlerMethodParameter类的子类
image.png
网友评论