Browse Source

Include only path in <spring:mvcUrl>

Issue: SPR-13045
pull/814/head
Rossen Stoyanchev 10 years ago
parent
commit
ad4c8795ae
  1. 8
      spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java
  2. 2
      spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilderTests.java

8
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java

@ -740,7 +740,7 @@ public class MvcUriComponentsBuilder { @@ -740,7 +740,7 @@ public class MvcUriComponentsBuilder {
public MethodArgumentBuilder(UriComponentsBuilder baseUrl, Class<?> controllerType, Method method) {
Assert.notNull(controllerType, "'controllerType' is required");
Assert.notNull(method, "'method' is required");
this.baseUrl = baseUrl;
this.baseUrl = (baseUrl != null ? baseUrl : initBaseUrl());
this.controllerType = controllerType;
this.method = method;
this.argumentValues = new Object[method.getParameterTypes().length];
@ -749,11 +749,17 @@ public class MvcUriComponentsBuilder { @@ -749,11 +749,17 @@ public class MvcUriComponentsBuilder {
}
}
private static UriComponentsBuilder initBaseUrl() {
UriComponentsBuilder builder = ServletUriComponentsBuilder.fromCurrentServletMapping();
return UriComponentsBuilder.fromPath(builder.build().getPath());
}
/**
* @deprecated as of 4.2 deprecated in favor of alternative constructors
* that accept the controllerType.
*/
@Deprecated
@SuppressWarnings("unused")
public MethodArgumentBuilder(Method method) {
this(method.getDeclaringClass(), method);
}

2
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilderTests.java

@ -312,7 +312,7 @@ public class MvcUriComponentsBuilderTests { @@ -312,7 +312,7 @@ public class MvcUriComponentsBuilderTests {
String mappingName = "PAC#getAddressesForCountry";
String url = MvcUriComponentsBuilder.fromMappingName(mappingName).arg(0, "DE").buildAndExpand(123);
assertEquals("http://example.org:9999/base/people/123/addresses/DE", url);
assertEquals("/base/people/123/addresses/DE", url);
}
@Test

Loading…
Cancel
Save