Merge branch '6.0.x'

This commit is contained in:
Stéphane Nicoll
2023-10-24 10:57:09 +02:00
4 changed files with 52 additions and 18 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
package org.springframework.web.reactive.result.method.annotation;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -71,12 +70,17 @@ public class MatrixVariableMapMethodArgumentResolver extends HandlerMethodArgume
Map<String, MultiValueMap<String, String>> matrixVariables =
exchange.getAttribute(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE);
MultiValueMap<String, String> map = mapMatrixVariables(parameter, matrixVariables);
return (isSingleValueMap(parameter) ? map.toSingleValueMap() : map);
}
if (CollectionUtils.isEmpty(matrixVariables)) {
return Collections.emptyMap();
}
private MultiValueMap<String,String> mapMatrixVariables(MethodParameter parameter,
@Nullable Map<String, MultiValueMap<String, String>> matrixVariables) {
MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
if (CollectionUtils.isEmpty(matrixVariables)) {
return map;
}
MatrixVariable annotation = parameter.getParameterAnnotation(MatrixVariable.class);
Assert.state(annotation != null, "No MatrixVariable annotation");
String pathVariable = annotation.pathVar();
@@ -84,7 +88,7 @@ public class MatrixVariableMapMethodArgumentResolver extends HandlerMethodArgume
if (!pathVariable.equals(ValueConstants.DEFAULT_NONE)) {
MultiValueMap<String, String> mapForPathVariable = matrixVariables.get(pathVariable);
if (mapForPathVariable == null) {
return Collections.emptyMap();
return map;
}
map.putAll(mapForPathVariable);
}
@@ -97,8 +101,7 @@ public class MatrixVariableMapMethodArgumentResolver extends HandlerMethodArgume
});
}
}
return (isSingleValueMap(parameter) ? map.toSingleValueMap() : map);
return map;
}
private boolean isSingleValueMap(MethodParameter parameter) {