SPR-8803 Refine UriComponentsBuilder.replaceQueryParam().

If no values are given, the query parameter is removed.
This commit is contained in:
Rossen Stoyanchev
2011-11-10 15:08:24 +00:00
parent dc88a7c8ba
commit 2a39f34d33
3 changed files with 16 additions and 6 deletions

View File

@@ -2905,11 +2905,14 @@ URI uri = uriComponents.expand("42", "21").encode().toUri();
<para>In a Servlet environment the
<classname>ServletUriComponentsBuilder</classname> sub-class provides
static factory methods to copy available URL information from a
Servlet request including host, scheme, port, path and query string:
Servlet requests:
</para>
<programlisting language="java">HttpServletRequest request = ...
// Re-use host, scheme, port, path and query string
// Replace the "accountId" query param
ServletUriComponentsBuilder ucb =
ServletUriComponentsBuilder.fromRequest(request).replaceQueryParam("accountId", "{id}").build()
.expand("123")
@@ -2919,7 +2922,9 @@ ServletUriComponentsBuilder ucb =
<para>Alternatively, you may choose to copy a subset of the available
information up to and including the context path:</para>
<programlisting language="java">// Host, port and context path
<programlisting language="java">// Re-use host, port and context path
// Append "/accounts" to the path
ServletUriComponentsBuilder ucb =
ServletUriComponentsBuilder.fromContextPath(request).path("/accounts").build()
</programlisting>
@@ -2928,7 +2933,10 @@ ServletUriComponentsBuilder ucb =
by name (e.g. <literal>/main/*</literal>), you can also have the literal part
of the servlet mapping included:</para>
<programlisting language="java">// Host, port, context path, and the literal part of the servlet mapping
<programlisting language="java">// Re-use host, port, context path
// Append the literal part of the servlet mapping to the path
// Append "/accounts" to the path
ServletUriComponentsBuilder ucb =
ServletUriComponentsBuilder.fromServletMapping(request).path("/accounts").build()
</programlisting>