@MatrixVariable resolvers for WebFlux
The information was already parsed and available in a request attribute but until now there were no argument resolvers to expose it. Issue: SPR-16005
This commit is contained in:
@@ -22,6 +22,7 @@ import java.util.function.Predicate;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.annotation.AnnotatedElementUtils;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.MatrixVariable;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -61,6 +62,9 @@ public class MvcAnnotationPredicates {
|
||||
return new RequestPartPredicate();
|
||||
}
|
||||
|
||||
public static MatrixVariablePredicate matrixAttribute() {
|
||||
return new MatrixVariablePredicate();
|
||||
}
|
||||
|
||||
// Method predicates
|
||||
|
||||
@@ -305,4 +309,40 @@ public class MvcAnnotationPredicates {
|
||||
}
|
||||
}
|
||||
|
||||
public static class MatrixVariablePredicate implements Predicate<MethodParameter> {
|
||||
|
||||
private String name;
|
||||
|
||||
private String pathVar;
|
||||
|
||||
|
||||
public MatrixVariablePredicate name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MatrixVariablePredicate noName() {
|
||||
this.name = "";
|
||||
return this;
|
||||
}
|
||||
|
||||
public MatrixVariablePredicate pathVar(String name) {
|
||||
this.pathVar = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MatrixVariablePredicate noPathVar() {
|
||||
this.pathVar = ValueConstants.DEFAULT_NONE;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(MethodParameter parameter) {
|
||||
MatrixVariable annotation = parameter.getParameterAnnotation(MatrixVariable.class);
|
||||
return annotation != null &&
|
||||
(this.name == null || this.name.equalsIgnoreCase(annotation.name())) &&
|
||||
(this.pathVar == null || this.pathVar.equalsIgnoreCase(annotation.pathVar()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user