#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:
committed by
Oliver Drotbohm
parent
9702527786
commit
a77c6e1593
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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}");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user