类 UriComponentsBuilder
- 所有已实现的接口:
UriBuilder,Cloneable
- 直接已知子类:
ServletUriComponentsBuilder
UriComponents.
Typical usage involves:
- Create a
UriComponentsBuilderwith one of the static factory methods (such asfromPath(String)orfromUri(URI)) - Set the various URI components through the respective methods (
scheme(String),userInfo(String),host(String),port(int),path(String),pathSegment(String...),queryParam(String, Object...), andfragment(String). - Build the
UriComponentsinstance with thebuild()method.
- 从以下版本开始:
- 4.0
- 作者:
- Arjen Poutsma, Rossen Stoyanchev, Phillip Webb, Oliver Gierke, Brian Clozel, Sebastien Deleuze, Sam Brannen, Harry Yang
- 另请参阅:
-
嵌套类概要
嵌套类修饰符和类型类说明private static classprivate static enumprivate static classprivate static interfaceprivate static class -
字段概要
字段修饰符和类型字段说明private Charsetprivate booleanprivate Stringprivate Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Patternprivate static final Stringprivate static final Stringprivate Stringprivate static final Stringprivate static final Patternprivate static final Stringprivate Stringprivate static final Stringprivate Stringprivate static final Patternprivate Stringprivate static final String -
构造器概要
构造器限定符构造器说明protectedDefault constructor.protectedCreate a deep copy of the given UriComponentsBuilder. -
方法概要
修饰符和类型方法说明build()Build aUriComponentsinstance from the various components contained in this builder.build(boolean encoded) Variant ofbuild()to create aUriComponentsinstance when components are already fully encoded.Build aURIinstance and replaces URI template variables with the values from an array.Build aURIinstance and replaces URI template variables with the values from a map.buildAndExpand(Object... uriVariableValues) Build aUriComponentsinstance and replaces URI template variables with the values from an array.buildAndExpand(Map<String, ?> uriVariables) Build aUriComponentsinstance and replaces URI template variables with the values from a map.private UriComponentsclone()Public declaration of Object'sclone()method.Clone thisUriComponentsBuilder.final UriComponentsBuilderencode()Request to have the URI template pre-encoded at build time, and URI variables encoded separately when expanded.A variant ofencode()with a charset other than "UTF-8".Set the URI fragment.static UriComponentsBuilderfromHttpRequest(HttpRequest request) Create a newUriComponentsobject from the URI associated with the given HttpRequest while also overlaying with values from the headers "Forwarded" (RFC 7239), or "X-Forwarded-Host", "X-Forwarded-Port", and "X-Forwarded-Proto" if "Forwarded" is not found.static UriComponentsBuilderfromHttpUrl(String httpUrl) Create a URI components builder from the given HTTP URL String.static UriComponentsBuilderfromOriginHeader(String origin) Create an instance by parsing the "Origin" header of an HTTP request.static UriComponentsBuilderCreate a builder that is initialized with the given path.static UriComponentsBuilderCreate a builder that is initialized from the givenURI.static UriComponentsBuilderfromUriString(String uri) Create a builder that is initialized with the given URI string.private StringgetQueryParamValue(Object value) Set the URI host which may contain URI template variables, and may also benullto clear the host of this builder.static UriComponentsBuilderCreate a new, empty builder.Append to the path of this builder.pathSegment(String... pathSegments) Append to the path using path segments.port(int port) Set the URI port.Set the URI port .Parse the given query string into query parameters where parameters are separated with'&'and their values, if any, with'='.queryParam(String name, Object... values) Append the given query parameter.queryParam(String name, Collection<?> values) Variant ofUriBuilder.queryParam(String, Object...)with a Collection.queryParamIfPresent(String name, Optional<?> value) Delegates to eitherUriBuilder.queryParam(String, Object...)orUriBuilder.queryParam(String, Collection)if the givenOptionalhas a value, or else if it is empty, no query parameter is added at all.queryParams(cn.taketoday.util.MultiValueMap<String, String> params) Add multiple query parameters and values.replacePath(String path) Override the current path.replaceQuery(String query) Clear existing query parameters and then delegate toUriBuilder.query(String).replaceQueryParam(String name, Object... values) Set the query parameter values replacing existing values, or if no values are given, the query parameter is removed.replaceQueryParam(String name, Collection<?> values) Variant ofUriBuilder.replaceQueryParam(String, Object...)with a Collection.replaceQueryParams(cn.taketoday.util.MultiValueMap<String, String> params) Set the query parameter values after removing all existing ones.private void(专用程序包) voidprivate voidSet the URI scheme which may contain URI template variables, and may also benullto clear the scheme of this builder.schemeSpecificPart(String ssp) Set the URI scheme-specific-part.Build a URI String.Initialize components of this builder from components of the given URI.uriComponents(UriComponents uriComponents) Set or append individual URI components of this builder from the values of the givenUriComponentsinstance.uriVariables(Map<String, Object> uriVariables) Configure URI variables to be expanded at build time.Set the URI user info which may contain URI template variables, and may also benullto clear the user info of this builder.
-
字段详细资料
-
QUERY_PARAM_PATTERN
-
SCHEME_PATTERN
- 另请参阅:
-
HTTP_PATTERN
- 另请参阅:
-
USERINFO_PATTERN
- 另请参阅:
-
HOST_IPV4_PATTERN
- 另请参阅:
-
HOST_IPV6_PATTERN
- 另请参阅:
-
HOST_PATTERN
- 另请参阅:
-
PORT_PATTERN
- 另请参阅:
-
PATH_PATTERN
- 另请参阅:
-
QUERY_PATTERN
- 另请参阅:
-
LAST_PATTERN
- 另请参阅:
-
URI_PATTERN
-
HTTP_URL_PATTERN
-
scheme
-
ssp
-
userInfo
-
host
-
port
-
pathBuilder
-
queryParams
-
fragment
-
uriVariables
-
encodeTemplate
private boolean encodeTemplate -
charset
-
-
构造器详细资料
-
UriComponentsBuilder
protected UriComponentsBuilder()Default constructor. Protected to prevent direct instantiation. -
UriComponentsBuilder
Create a deep copy of the given UriComponentsBuilder.- 参数:
other- the other builder to copy from
-
-
方法详细资料
-
newInstance
Create a new, empty builder.- 返回:
- the new
UriComponentsBuilder
-
fromPath
Create a builder that is initialized with the given path.- 参数:
path- the path to initialize with- 返回:
- the new
UriComponentsBuilder
-
fromUri
Create a builder that is initialized from the givenURI.Note: the components in the resulting builder will be in fully encoded (raw) form and further changes must also supply values that are fully encoded, for example via methods in
UriUtils. In addition please usebuild(boolean)with a value of "true" to build theUriComponentsinstance in order to indicate that the components are encoded.- 参数:
uri- the URI to initialize with- 返回:
- the new
UriComponentsBuilder
-
fromUriString
Create a builder that is initialized with the given URI string.Note: The presence of reserved characters can prevent correct parsing of the URI string. For example if a query parameter contains
'='or'&'characters, the query string cannot be parsed unambiguously. Such values should be substituted for URI variables to enable correct parsing:String uriString = "/hotels/42?filter={value}"; UriComponentsBuilder.fromUriString(uriString).buildAndExpand("hot&cold");- 参数:
uri- the URI string to initialize with- 返回:
- the new
UriComponentsBuilder
-
fromHttpUrl
Create a URI components builder from the given HTTP URL String.Note: The presence of reserved characters can prevent correct parsing of the URI string. For example if a query parameter contains
'='or'&'characters, the query string cannot be parsed unambiguously. Such values should be substituted for URI variables to enable correct parsing:String urlString = "https://example.com/hotels/42?filter={value}"; UriComponentsBuilder.fromHttpUrl(urlString).buildAndExpand("hot&cold");- 参数:
httpUrl- the source URI- 返回:
- the URI components of the URI
-
fromHttpRequest
Create a newUriComponentsobject from the URI associated with the given HttpRequest while also overlaying with values from the headers "Forwarded" (RFC 7239), or "X-Forwarded-Host", "X-Forwarded-Port", and "X-Forwarded-Proto" if "Forwarded" is not found.- 参数:
request- the source request- 返回:
- the URI components of the URI
-
fromOriginHeader
Create an instance by parsing the "Origin" header of an HTTP request.- 另请参阅:
-
encode
Request to have the URI template pre-encoded at build time, and URI variables encoded separately when expanded.In comparison to
UriComponents.encode(), this method has the same effect on the URI template, i.e. each URI component is encoded by replacing non-ASCII and illegal (within the URI component type) characters with escaped octets. However URI variables are encoded more strictly, by also escaping characters with reserved meaning.For most cases, this method is more likely to give the expected result because in treats URI variables as opaque data to be fully encoded, while
UriComponents.encode()is useful when intentionally expanding URI variables that contain reserved characters.For example ';' is legal in a path but has reserved meaning. This method replaces ";" with "%3B" in URI variables but not in the URI template. By contrast,
UriComponents.encode()never replaces ";" since it is a legal character in a path.When not expanding URI variables at all, prefer use of
UriComponents.encode()since that will also encode anything that incidentally looks like a URI variable. -
encode
A variant ofencode()with a charset other than "UTF-8".- 参数:
charset- the charset to use for encoding
-
build
Build aUriComponentsinstance from the various components contained in this builder.- 返回:
- the URI components
-
build
Variant ofbuild()to create aUriComponentsinstance when components are already fully encoded. This is useful for example if the builder was created viafromUri(URI).- 参数:
encoded- whether the components in this builder are already encoded- 返回:
- the URI components
- 抛出:
IllegalArgumentException- if any of the components contain illegal characters that should have been encoded.
-
buildInternal
-
buildAndExpand
Build aUriComponentsinstance and replaces URI template variables with the values from a map. This is a shortcut method which combines calls tobuild()and thenUriComponents.expand(Map).- 参数:
uriVariables- the map of URI variables- 返回:
- the URI components with expanded values
-
buildAndExpand
Build aUriComponentsinstance and replaces URI template variables with the values from an array. This is a shortcut method which combines calls tobuild()and thenUriComponents.expand(Object...).- 参数:
uriVariableValues- the URI variable values- 返回:
- the URI components with expanded values
-
build
从接口复制的说明:UriBuilderBuild aURIinstance and replaces URI template variables with the values from an array.- 指定者:
build在接口中UriBuilder- 参数:
uriVariables- the map of URI variables- 返回:
- the URI
-
build
从接口复制的说明:UriBuilderBuild aURIinstance and replaces URI template variables with the values from a map.- 指定者:
build在接口中UriBuilder- 参数:
uriVariables- the map of URI variables- 返回:
- the URI
-
toUriString
Build a URI String.Effectively, a shortcut for building, encoding, and returning the String representation:
String uri = builder.build().encode().toUriString()
However if
URI variableshave been provided then the URI template is pre-encoded separately from URI variables (seeencode()for details), i.e. equivalent to:String uri = builder.encode().build().toUriString()
-
uri
Initialize components of this builder from components of the given URI.- 参数:
uri- the URI- 返回:
- this UriComponentsBuilder
-
uriComponents
Set or append individual URI components of this builder from the values of the givenUriComponentsinstance.For the semantics of each component (i.e. set vs append) check the builder methods on this class. For example
host(String)sets whilepath(String)appends.- 参数:
uriComponents- the UriComponents to copy from- 返回:
- this UriComponentsBuilder
-
scheme
从接口复制的说明:UriBuilderSet the URI scheme which may contain URI template variables, and may also benullto clear the scheme of this builder.- 指定者:
scheme在接口中UriBuilder- 参数:
scheme- the URI scheme
-
schemeSpecificPart
Set the URI scheme-specific-part. When invoked, this method overwrites user-info, host, port, path, andquery.- 参数:
ssp- the URI scheme-specific-part, may contain URI template parameters- 返回:
- this UriComponentsBuilder
-
userInfo
从接口复制的说明:UriBuilderSet the URI user info which may contain URI template variables, and may also benullto clear the user info of this builder.- 指定者:
userInfo在接口中UriBuilder- 参数:
userInfo- the URI user info
-
host
从接口复制的说明:UriBuilderSet the URI host which may contain URI template variables, and may also benullto clear the host of this builder.- 指定者:
host在接口中UriBuilder- 参数:
host- the URI host
-
port
从接口复制的说明:UriBuilderSet the URI port. Passing-1will clear the port of this builder.- 指定者:
port在接口中UriBuilder- 参数:
port- the URI port
-
port
从接口复制的说明:UriBuilderSet the URI port . Use this method only when the port needs to be parameterized with a URI variable. Otherwise useUriBuilder.port(int). Passingnullwill clear the port of this builder.- 指定者:
port在接口中UriBuilder- 参数:
port- the URI port
-
path
从接口复制的说明:UriBuilderAppend to the path of this builder.The given value is appended as-is to previous
pathvalues without inserting any additional slashes. For example:builder.path("/first-").path("value/").path("/{id}").build("123") // Results is "/first-value/123"By contrast
pathSegmentdoes insert slashes between individual path segments. For example:builder.pathSegment("first-value", "second-value").path("/") // Results is "/first-value/second-value/"The resulting full path is normalized to eliminate duplicate slashes.
Note: When inserting a URI variable value that contains slashes in a
path, whether those are encoded depends on the configured encoding mode. For more details, seeencode(), or otherwise if building URIs indirectly viaWebClientorRestTemplate, see itsencodingMode. Also see the URI Encoding section of the reference docs.- 指定者:
path在接口中UriBuilder- 参数:
path- the URI path
-
pathSegment
从接口复制的说明:UriBuilderAppend to the path using path segments. For example:builder.pathSegment("first-value", "second-value", "{id}").build("123") // Results is "/first-value/second-value/123"If slashes are present in a path segment, they are encoded:
builder.pathSegment("ba/z", "{id}").build("a/b") // Results is "/ba%2Fz/a%2Fb"To insert a trailing slash, use theUriBuilder.path(java.lang.String)builder method:builder.pathSegment("first-value", "second-value").path("/") // Results is "/first-value/second-value/"Empty path segments are ignored and therefore duplicate slashes do not appear in the resulting full path.
- 指定者:
pathSegment在接口中UriBuilder- 参数:
pathSegments- the URI path segments- 抛出:
IllegalArgumentException
-
replacePath
从接口复制的说明:UriBuilderOverride the current path.- 指定者:
replacePath在接口中UriBuilder- 参数:
path- the URI path, ornullfor an empty path
-
query
从接口复制的说明:UriBuilderParse the given query string into query parameters where parameters are separated with'&'and their values, if any, with'='. The query may contain URI template variables.Note: please, review the Javadoc of
UriBuilder.queryParam(String, Object...)for further notes on the treatment and encoding of individual query parameters.- 指定者:
query在接口中UriBuilder- 参数:
query- the query string
-
replaceQuery
从接口复制的说明:UriBuilderClear existing query parameters and then delegate toUriBuilder.query(String).Note: please, review the Javadoc of
UriBuilder.queryParam(String, Object...)for further notes on the treatment and encoding of individual query parameters.- 指定者:
replaceQuery在接口中UriBuilder- 参数:
query- the query string; anullvalue removes all query parameters.
-
queryParam
从接口复制的说明:UriBuilderAppend the given query parameter. Both the parameter name and values may contain URI template variables to be expanded later from values. If no values are given, the resulting URI will contain the query parameter name only, e.g."?foo"instead of"?foo=bar".Note: encoding, if applied, will only encode characters that are illegal in a query parameter name or value such as
"="or"&". All others that are legal as per syntax rules in RFC 3986 are not encoded. This includes"+"which sometimes needs to be encoded to avoid its interpretation as an encoded space. Stricter encoding may be applied by using a URI template variable along with stricter encoding on variable values. For more details please read the "URI Encoding" section of the Framework reference.- 指定者:
queryParam在接口中UriBuilder- 参数:
name- the query parameter namevalues- the query parameter values- 另请参阅:
-
getQueryParamValue
-
queryParam
从接口复制的说明:UriBuilderVariant ofUriBuilder.queryParam(String, Object...)with a Collection.Note: please, review the Javadoc of
UriBuilder.queryParam(String, Object...)for further notes on the treatment and encoding of individual query parameters.- 指定者:
queryParam在接口中UriBuilder- 参数:
name- the query parameter namevalues- the query parameter values- 另请参阅:
-
queryParamIfPresent
从接口复制的说明:UriBuilderDelegates to eitherUriBuilder.queryParam(String, Object...)orUriBuilder.queryParam(String, Collection)if the givenOptionalhas a value, or else if it is empty, no query parameter is added at all.- 指定者:
queryParamIfPresent在接口中UriBuilder- 参数:
name- the query parameter namevalue- an Optional, either empty or holding the query parameter value.
-
queryParams
public UriComponentsBuilder queryParams(@Nullable cn.taketoday.util.MultiValueMap<String, String> params) Add multiple query parameters and values.Note: please, review the Javadoc of
UriBuilder.queryParam(String, Object...)for further notes on the treatment and encoding of individual query parameters.- 指定者:
queryParams在接口中UriBuilder- 参数:
params- the params
-
replaceQueryParam
从接口复制的说明:UriBuilderSet the query parameter values replacing existing values, or if no values are given, the query parameter is removed.Note: please, review the Javadoc of
UriBuilder.queryParam(String, Object...)for further notes on the treatment and encoding of individual query parameters.- 指定者:
replaceQueryParam在接口中UriBuilder- 参数:
name- the query parameter namevalues- the query parameter values- 另请参阅:
-
replaceQueryParam
从接口复制的说明:UriBuilderVariant ofUriBuilder.replaceQueryParam(String, Object...)with a Collection.Note: please, review the Javadoc of
UriBuilder.queryParam(String, Object...)for further notes on the treatment and encoding of individual query parameters.- 指定者:
replaceQueryParam在接口中UriBuilder- 参数:
name- the query parameter namevalues- the query parameter values- 另请参阅:
-
replaceQueryParams
public UriComponentsBuilder replaceQueryParams(@Nullable cn.taketoday.util.MultiValueMap<String, String> params) Set the query parameter values after removing all existing ones.Note: please, review the Javadoc of
UriBuilder.queryParam(String, Object...)for further notes on the treatment and encoding of individual query parameters.- 指定者:
replaceQueryParams在接口中UriBuilder- 参数:
params- the query parameter name
-
fragment
从接口复制的说明:UriBuilderSet the URI fragment. The given fragment may contain URI template variables, and may also benullto clear the fragment of this builder.- 指定者:
fragment在接口中UriBuilder- 参数:
fragment- the URI fragment
-
uriVariables
Configure URI variables to be expanded at build time.The provided variables may be a subset of all required ones. At build time, the available ones are expanded, while unresolved URI placeholders are left in place and can still be expanded later.
In contrast to
UriComponents.expand(Map)orbuildAndExpand(Map), this method is useful when you need to supply URI variables without building theUriComponentsinstance just yet, or perhaps pre-expand some shared default values such as host and port.- 参数:
uriVariables- the URI variables to use- 返回:
- this UriComponentsBuilder
-
resetHierarchicalComponents
private void resetHierarchicalComponents() -
resetSchemeSpecificPart
private void resetSchemeSpecificPart() -
resetPortIfDefaultForScheme
void resetPortIfDefaultForScheme() -
clone
Public declaration of Object'sclone()method. Delegates tocloneBuilder(). -
cloneBuilder
Clone thisUriComponentsBuilder.- 返回:
- the cloned
UriComponentsBuilderobject
-