Skip to content

Commit 19dab82

Browse files
committed
Add test for resolving RequestParam through SpEL
Signed-off-by: 秦利斌 <[email protected]>
1 parent 29521e2 commit 19dab82

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

spring-web/src/test/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolverTests.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,14 @@ void supportsParameter() {
159159
param = this.testMethod.annotPresent(RequestPart.class).arg(MultipartFile.class);
160160
assertThat(resolver.supportsParameter(param)).isFalse();
161161

162-
param = this.testMethod.annotPresent(RequestParam.class).arg(Integer.class);
162+
param = this.testMethod.annot(requestParam().name("${systemProperty}")).arg(Integer.class);
163163
assertThat(resolver.supportsParameter(param)).isTrue();
164164

165165
param = this.testMethod.annotPresent(RequestParam.class).arg(int.class);
166166
assertThat(resolver.supportsParameter(param)).isTrue();
167+
168+
param = this.testMethod.annot(requestParam().name("#{'na'.concat('me')}")).arg(Integer.class);
169+
assertThat(resolver.supportsParameter(param)).isTrue();
167170
}
168171

169172
@Test
@@ -715,6 +718,21 @@ void notNullablePrimitiveParameterFromSystemPropertyThroughPlaceholder() {
715718
System.clearProperty("systemProperty");
716719
}
717720

721+
@Test
722+
void resolveNameThroughSpEL() throws Exception{
723+
ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
724+
initializer.setConversionService(new DefaultConversionService());
725+
WebDataBinderFactory binderFactory = new DefaultDataBinderFactory(initializer);
726+
727+
Integer expected = 100;
728+
request.addParameter("name", expected.toString());
729+
730+
MethodParameter param = this.testMethod.annot(requestParam().name("#{'na'.concat('me')}")).arg(Integer.class);
731+
Object result = resolver.resolveArgument(param, null, webRequest, binderFactory);
732+
assertThat(result).isEqualTo(100);
733+
734+
}
735+
718736
@SuppressWarnings({"unused", "OptionalUsedAsFieldOrParameterType"})
719737
public void handle(
720738
@RequestParam(name = "name", defaultValue = "bar") String param1,
@@ -740,7 +758,9 @@ public void handle(
740758
@RequestParam("mfile") Optional<MultipartFile> multipartFileOptional,
741759
@RequestParam(defaultValue = "false") Boolean booleanParam,
742760
@RequestParam("${systemProperty}") Integer placeholderParam,
743-
@RequestParam(name = "${systemProperty}", required = false) int primitivePlaceholderParam) {
761+
@RequestParam(name = "${systemProperty}", required = false) int primitivePlaceholderParam,
762+
@RequestParam("#{'na'.concat('me')}") Integer spelParam
763+
) {
744764
}
745765

746766
}

0 commit comments

Comments
 (0)