#1561 - Support for implicitly not required request parameters.
Handler method parameters annotated with @RequestParam(defaultValue = …) are implicitly not required and thus should still be advertised in the URI templated generated. Previously it was necessary to explicitly set @RequestParam(required = …) to false. Original pull request: #1511. Related ticket: #331.
This commit is contained in:
committed by
Oliver Drotbohm
parent
dd51b54204
commit
9ee4b8e1ec
@@ -460,7 +460,7 @@ public class WebHandler {
|
||||
|
||||
RequestParam annotation = parameter.getParameterAnnotation(RequestParam.class);
|
||||
|
||||
if (!(annotation != null && annotation.required()) || parameter.isOptional()) {
|
||||
if (!isRequired() || parameter.isOptional()) {
|
||||
return SKIP_VALUE;
|
||||
}
|
||||
|
||||
|
||||
@@ -465,14 +465,14 @@ class WebMvcLinkBuilderUnitTest extends TestUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #331
|
||||
* @see #331, #545
|
||||
*/
|
||||
@Test
|
||||
void linksToMethodWithRequestParamImplicitlySetToFalse() {
|
||||
|
||||
Link link = linkTo(methodOn(ControllerWithMethods.class).methodForOptionalSizeWithDefaultValue(null)).withSelfRel();
|
||||
|
||||
assertThat(link.getHref()).endsWith("/bar");
|
||||
assertThat(link.getHref()).endsWith("/bar{?size}");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user