SPR-8020 Support UriComponentsBuilder as a controller method argument.
The UriComponentsBuilder instance passed into the method is initialized with current request information including host, scheme, port, context path, and the servlet mapping's literal part. Also added shortcut methods to buildAndExpand in UriComponentsBuilder.
This commit is contained in:
@@ -130,6 +130,9 @@ import java.lang.annotation.Target;
|
||||
* for marking form processing as complete (triggering the cleanup of session
|
||||
* attributes that have been indicated by the {@link SessionAttributes} annotation
|
||||
* at the handler type level).
|
||||
* <li>{@link org.springframework.web.util.UriComponentsBuilder} a builder for
|
||||
* preparing a URL relative to the current request's host, port, scheme, context
|
||||
* path, and the literal part of the servlet mapping.
|
||||
* </ul>
|
||||
*
|
||||
* <p>The following return types are supported for handler methods:
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -221,6 +222,30 @@ public class UriComponentsBuilder {
|
||||
return new UriComponents(scheme, userInfo, host, port, pathBuilder.build(), queryParams, fragment, encoded, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a {@code UriComponents} instance and replaces URI template variables
|
||||
* with the values from a map. This is a shortcut method, which combines
|
||||
* calls to {@link #build()} and then {@link UriComponents#expand(Map)}.
|
||||
*
|
||||
* @param uriVariables the map of URI variables
|
||||
* @return the URI components with expanded values
|
||||
*/
|
||||
public UriComponents buildAndExpand(Map<String, ?> uriVariables) {
|
||||
return build(false).expand(uriVariables);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a {@code UriComponents} instance and replaces URI template variables
|
||||
* with the values from an array. This is a shortcut method, which combines
|
||||
* calls to {@link #build()} and then {@link UriComponents#expand(Object...)}.
|
||||
*
|
||||
* @param uriVariableValues URI variable values
|
||||
* @return the URI components with expanded values
|
||||
*/
|
||||
public UriComponents buildAndExpand(Object... uriVariableValues) {
|
||||
return build(false).expand(uriVariableValues);
|
||||
}
|
||||
|
||||
// URI components methods
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user