springMVC数据绑定原理梳理:
1、流程梳理
DispatcherServlet
mv = ha.handle(processedRequest, response, mappedHandler.getHandler());
InvocableHandlerMethod
public Object invokeForRequest(NativeWebRequest request, ModelAndViewContainer mavContainer,
Object... providedArgs) throws Exception {
Object[] args = getMethodArgumentValues(request, mavContainer, providedArgs);
Object returnValue = doInvoke(args);
return returnValue;
}
Invoke the method after resolving its argument values in the context of the given request
在给定请求的上下文中解析该方法的参数值后调用该方法
InvocableHandlerMethod
private Object[] getMethodArgumentValues(NativeWebRequest request, ModelAndViewContainer mavContainer,
Object... providedArgs) throws Exception {
//从HandlerMethod获取方法的参数
MethodParameter[] parameters = getMethodParameters();
Object[] args = new Object[parameters.length];
for (int i = 0; i < parameters.length; i++) {
MethodParameter parameter = parameters[i];
//初始化一个通过方法名称解析方法参数名称的解析器《ParameterNameDiscoverer》
parameter.initParameterNameDiscovery(this.parameterNameDiscoverer);
//解析泛型的实际参数类型
GenericTypeResolver.resolveParameterType(parameter, getBean().getClass()