Introduce alias for 'value' attribute in @CookieValue
Issue: SPR-11393
This commit is contained in:
parent
845f4f2bb7
commit
c4c3ce796a
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 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,14 +22,18 @@ 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 an HTTP cookie.
|
||||
* Supported for annotated handler methods in Servlet and Portlet environments.
|
||||
*
|
||||
* <p>Supported for annotated handler methods in Servlet and Portlet environments.
|
||||
*
|
||||
* <p>The method parameter may be declared as type {@link javax.servlet.http.Cookie}
|
||||
* or as cookie value type (String, int, etc).
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
* @since 3.0
|
||||
* @see RequestMapping
|
||||
* @see RequestParam
|
||||
|
@ -45,10 +49,18 @@ import java.lang.annotation.Target;
|
|||
public @interface CookieValue {
|
||||
|
||||
/**
|
||||
* The name of the cookie to bind to.
|
||||
* Alias for {@link #name}.
|
||||
*/
|
||||
@AliasFor(attribute = "name")
|
||||
String value() default "";
|
||||
|
||||
/**
|
||||
* The name of the cookie to bind to.
|
||||
* @since 4.2
|
||||
*/
|
||||
@AliasFor(attribute = "value")
|
||||
String name() default "";
|
||||
|
||||
/**
|
||||
* Whether the header is required.
|
||||
* <p>Default is {@code true}, leading to an exception being thrown
|
||||
|
|
|
@ -278,7 +278,7 @@ public class HandlerMethodInvoker {
|
|||
}
|
||||
else if (CookieValue.class.isInstance(paramAnn)) {
|
||||
CookieValue cookieValue = (CookieValue) paramAnn;
|
||||
cookieName = cookieValue.value();
|
||||
cookieName = cookieValue.name();
|
||||
required = cookieValue.required();
|
||||
defaultValue = parseDefaultValueAttribute(cookieValue.defaultValue());
|
||||
annotationsFound++;
|
||||
|
|
|
@ -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.
|
||||
|
@ -70,7 +70,7 @@ public abstract class AbstractCookieValueMethodArgumentResolver extends Abstract
|
|||
private static class CookieValueNamedValueInfo extends NamedValueInfo {
|
||||
|
||||
private CookieValueNamedValueInfo(CookieValue annotation) {
|
||||
super(annotation.value(), annotation.required(), annotation.defaultValue());
|
||||
super(annotation.name(), annotation.required(), annotation.defaultValue());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
@ -99,7 +99,7 @@ public class CookieValueMethodArgumentResolverTests {
|
|||
}
|
||||
|
||||
public void params(@CookieValue("name") Cookie param1,
|
||||
@CookieValue(value = "name", defaultValue = "bar") String param2,
|
||||
@CookieValue(name = "name", defaultValue = "bar") String param2,
|
||||
String param3) {
|
||||
}
|
||||
|
||||
|
|
|
@ -1657,7 +1657,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
|||
|
||||
@RequestMapping("/myPath2.do")
|
||||
public void myHandle(@RequestParam("param1") String p1, @RequestParam("param2") int p2,
|
||||
@RequestHeader("header1") long h1, @CookieValue("cookie1") Cookie c1,
|
||||
@RequestHeader("header1") long h1, @CookieValue(name = "cookie1") Cookie c1,
|
||||
HttpServletResponse response) throws IOException {
|
||||
response.getWriter().write("test-" + p1 + "-" + p2 + "-" + h1 + "-" + c1.getValue());
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ public class ServletCookieValueMethodArgumentResolverTests {
|
|||
}
|
||||
|
||||
public void params(@CookieValue("name") Cookie cookie,
|
||||
@CookieValue(value = "name", defaultValue = "bar") String cookieString) {
|
||||
@CookieValue(name = "name", defaultValue = "bar") String cookieString) {
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue