#545 - 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:
Florian Cramer
2021-04-10 22:47:08 +02:00
committed by Oliver Drotbohm
parent 9702527786
commit a77c6e1593
2 changed files with 3 additions and 3 deletions

View File

@@ -474,7 +474,7 @@ public class WebHandler {
RequestParam annotation = parameter.getParameterAnnotation(RequestParam.class);
if (!(annotation != null && annotation.required()) || parameter.isOptional()) {
if (!isRequired() || parameter.isOptional()) {
return SKIP_VALUE;
}

View File

@@ -471,14 +471,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}");
}
/**