WebDataBinder componentBinder = binderFactory.createBinder(request, component, null);
component = componentBinder.getTarget();
if (component != null) {
ServletRequestParameterPropertyValues pvs = new ServletRequestParameterPropertyValues(servletRequest, prefixName, "");
componentBinder.bind(pvs);
validateIfApplicable(componentBinder, parameter);
if (componentBinder.getBindingResult().hasErrors()) {
if (isBindExceptionRequired(componentBinder, parameter)) {
throw new BindException(componentBinder.getBindingResult());
}
}
targetList.set(index, component);
}
}
target.clear();
target.addAll(targetList);
}
} else if (MapWapper.class.isAssignableFrom(targetType)) {
Type type = parameter.getGenericParameterType();
Class<?> keyType = Object.class;
Class<?> valueType = Object.class;
if (type instanceof ParameterizedType) {
keyType = (Class<?>) ((ParameterizedType) type).getActualTypeArguments()[0];
valueType = (Class<?>) ((ParameterizedType) type).getActualTypeArguments()[1];
}
MapWapper mapWapper = ((MapWapper) binder.getTarget());
Map target = mapWapper.getInnerMap();
if(target == null) {
target = new HashMap();
mapWapper.setInnerMap(target);
}
for (Object key : servletRequest.getParameterMap().keySet()) {
String prefixName = getPrefixName((String) key);
//每个prefix 只处理一次
if (hasProcessedPrefixMap.containsKey(prefixName)) {
continue;
} else {
hasProcessedPrefixMap.put(prefixName, Boolean.TRUE);
}
Object keyValue = simpleBinder.convertIfNecessary(getMapKey(prefixName), keyType);
if (isSimpleComponent(prefixName)) { //bind simple type
Map<String, Object> paramValues = WebUtils.getParametersStartingWith(servletRequest, prefixName);
for (Object value : paramValues.values()) {
target.put(keyValue, simpleBinder.convertIfNecessary(value, valueType));
}
} else {
Object component = target.get(keyValue);
if(component == null) {
component = BeanUtils.instantiate(valueType);
}
WebDataBinder componentBinder = binderFactory.createBinder(request, component, null);
component = componentBinder.getTarget();
if (component != null) {
ServletRequestParameterPropertyValues pvs = new ServletRequestParameterPropertyValues(servletRequest, prefixName, "");
componentBinder.bind(pvs);
validateComponent(componentBinder, parameter);
target.put(keyValue, component);