#331 - Fixed handling of @RequestParam with default value set.

ControllerLinkBuilderFactory now checks the default value of an @RequestParam annotated handler method parameter before triggering strict validation.

Original pull request: #332.
This commit is contained in:
Oemer Yildiz
2015-04-13 14:41:08 +02:00
committed by Oliver Gierke
parent 22488e0c05
commit 312fa3ead9
2 changed files with 22 additions and 2 deletions

View File

@@ -41,6 +41,7 @@ import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ValueConstants;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import org.springframework.web.util.UriTemplate;
@@ -53,6 +54,7 @@ import org.springframework.web.util.UriTemplate;
* @author Dietrich Schulten
* @author Kamill Sokol
* @author Ross Turner
* @author Oemer Yildiz
*/
public class ControllerLinkBuilderFactory implements MethodLinkBuilderFactory<ControllerLinkBuilder> {
@@ -233,7 +235,8 @@ public class ControllerLinkBuilderFactory implements MethodLinkBuilderFactory<Co
protected Object verifyParameterValue(MethodParameter parameter, Object value) {
RequestParam annotation = parameter.getParameterAnnotation(RequestParam.class);
return annotation.required() ? super.verifyParameterValue(parameter, value) : value;
return annotation.required() && annotation.defaultValue().equals(ValueConstants.DEFAULT_NONE) ? super
.verifyParameterValue(parameter, value) : value;
}
}
}