diff --git a/spring-web/src/main/java/org/springframework/web/bind/annotation/MatrixVariable.java b/spring-web/src/main/java/org/springframework/web/bind/annotation/MatrixVariable.java index 6ae0d7e1c9..2cfc22a91d 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/annotation/MatrixVariable.java +++ b/spring-web/src/main/java/org/springframework/web/bind/annotation/MatrixVariable.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -22,6 +22,8 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import org.springframework.core.annotation.AliasFor; + /** * Annotation which indicates that a method parameter should be bound to a * name-value pair within a path segment. Supported for {@link RequestMapping} @@ -37,6 +39,7 @@ import java.lang.annotation.Target; * matrix variable names and values. * * @author Rossen Stoyanchev + * @author Sam Brannen * @since 3.2 */ @Target(ElementType.PARAMETER) @@ -45,10 +48,19 @@ import java.lang.annotation.Target; public @interface MatrixVariable { /** - * The name of the matrix variable. + * Alias for {@link #name}. */ + @AliasFor(attribute = "name") String value() default ""; + /** + * The name of the matrix variable. + * @since 4.2 + * @see #value + */ + @AliasFor(attribute = "value") + String name() default ""; + /** * The name of the URI path variable where the matrix variable is located, * if necessary for disambiguation (e.g. a matrix variable with the same @@ -58,17 +70,18 @@ public @interface MatrixVariable { /** * Whether the matrix variable is required. - *
Default is {@code true}, leading to an exception thrown in case - * of the variable missing in the request. Switch this to {@code false} - * if you prefer a {@code null} in case of the variable missing. - *
Alternatively, provide a {@link #defaultValue() defaultValue}, - * which implicitly sets this flag to {@code false}. + *
Default is {@code true}, leading to an exception being thrown in + * case the variable is missing in the request. Switch this to {@code false} + * if you prefer a {@code null} if the variable is missing. + *
Alternatively, provide a {@link #defaultValue}, which implicitly sets + * this flag to {@code false}. */ boolean required() default true; /** - * The default value to use as a fallback. Supplying a default value implicitly - * sets {@link #required()} to false. + * The default value to use as a fallback. + *
Supplying a default value implicitly sets {@link #required} to + * {@code false}. */ String defaultValue() default ValueConstants.DEFAULT_NONE; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariableMapMethodArgumentResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariableMapMethodArgumentResolver.java index ffefd91786..59a8e9874f 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariableMapMethodArgumentResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariableMapMethodArgumentResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2015 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. @@ -35,8 +35,8 @@ import org.springframework.web.servlet.HandlerMapping; /** * Resolves method arguments of type Map annotated with - * {@link MatrixVariable @MatrixVariable} where the annotation the does not - * specify a name. If a name specified then the argument will by resolved by the + * {@link MatrixVariable @MatrixVariable} where the annotation does not + * specify a name. If a name is specified then the argument will by resolved by the * {@link MatrixVariableMethodArgumentResolver} instead. * * @author Rossen Stoyanchev @@ -46,10 +46,10 @@ public class MatrixVariableMapMethodArgumentResolver implements HandlerMethodArg @Override public boolean supportsParameter(MethodParameter parameter) { - MatrixVariable paramAnnot = parameter.getParameterAnnotation(MatrixVariable.class); - if (paramAnnot != null) { + MatrixVariable matrixVariable = parameter.getParameterAnnotation(MatrixVariable.class); + if (matrixVariable != null) { if (Map.class.isAssignableFrom(parameter.getParameterType())) { - return !StringUtils.hasText(paramAnnot.value()); + return !StringUtils.hasText(matrixVariable.name()); } } return false; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariableMethodArgumentResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariableMethodArgumentResolver.java index 8e563d22c2..31f44a6e64 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariableMethodArgumentResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariableMethodArgumentResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -33,12 +33,13 @@ import org.springframework.web.method.annotation.AbstractNamedValueMethodArgumen import org.springframework.web.servlet.HandlerMapping; /** - * Resolves method arguments annotated with an {@link MatrixVariable @PathParam}. + * Resolves method arguments annotated with {@link MatrixVariable @MatrixVariable}. * *
If the method parameter is of type Map and no name is specified, then it will
* by resolved by the {@link MatrixVariableMapMethodArgumentResolver} instead.
*
* @author Rossen Stoyanchev
+ * @author Sam Brannen
* @since 3.2
*/
public class MatrixVariableMethodArgumentResolver extends AbstractNamedValueMethodArgumentResolver {
@@ -53,8 +54,8 @@ public class MatrixVariableMethodArgumentResolver extends AbstractNamedValueMeth
return false;
}
if (Map.class.isAssignableFrom(parameter.getParameterType())) {
- String paramName = parameter.getParameterAnnotation(MatrixVariable.class).value();
- return StringUtils.hasText(paramName);
+ String variableName = parameter.getParameterAnnotation(MatrixVariable.class).name();
+ return StringUtils.hasText(variableName);
}
return true;
}
@@ -62,7 +63,7 @@ public class MatrixVariableMethodArgumentResolver extends AbstractNamedValueMeth
@Override
protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) {
MatrixVariable annotation = parameter.getParameterAnnotation(MatrixVariable.class);
- return new PathParamNamedValueInfo(annotation);
+ return new MatrixVariableNamedValueInfo(annotation);
}
@Override
@@ -120,10 +121,10 @@ public class MatrixVariableMethodArgumentResolver extends AbstractNamedValueMeth
}
- private static class PathParamNamedValueInfo extends NamedValueInfo {
+ private static class MatrixVariableNamedValueInfo extends NamedValueInfo {
- private PathParamNamedValueInfo(MatrixVariable annotation) {
- super(annotation.value(), annotation.required(), annotation.defaultValue());
+ private MatrixVariableNamedValueInfo(MatrixVariable annotation) {
+ super(annotation.name(), annotation.required(), annotation.defaultValue());
}
}
}
\ No newline at end of file
diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariablesMethodArgumentResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariablesMethodArgumentResolverTests.java
index e4d0958541..f3630df478 100644
--- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariablesMethodArgumentResolverTests.java
+++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariablesMethodArgumentResolverTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2015 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.
@@ -152,7 +152,7 @@ public class MatrixVariablesMethodArgumentResolverTests {
public void handle(
String stringArg,
@MatrixVariable List