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

View File

@@ -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;
}

View File

@@ -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}");
}
/**