Fix ServletUriComponentsBuilder examples in ref docs

Closes gh-27984
This commit is contained in:
wkwkhautbois 2022-01-28 23:06:32 +09:00 committed by Sam Brannen
parent caa13690e8
commit fadfcf4e43
1 changed files with 26 additions and 20 deletions

View File

@ -4109,10 +4109,9 @@ as the following example shows:
// Re-uses host, scheme, port, path and query string...
ServletUriComponentsBuilder ucb = ServletUriComponentsBuilder.fromRequest(request)
.replaceQueryParam("accountId", "{id}").build()
.expand("123")
.encode();
URI uri = ServletUriComponentsBuilder.fromRequest(request)
.replaceQueryParam("accountId", "{id}")
.build("123");
----
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin
@ -4121,10 +4120,9 @@ as the following example shows:
// Re-uses host, scheme, port, path and query string...
val ucb = ServletUriComponentsBuilder.fromRequest(request)
.replaceQueryParam("accountId", "{id}").build()
.expand("123")
.encode()
val uri = ServletUriComponentsBuilder.fromRequest(request)
.replaceQueryParam("accountId", "{id}")
.build("123")
----
You can create URIs relative to the context path, as the following example shows:
@ -4132,18 +4130,22 @@ You can create URIs relative to the context path, as the following example shows
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
----
// Re-uses host, port and context path...
// Re-uses host, port, scheme and context path...
ServletUriComponentsBuilder ucb = ServletUriComponentsBuilder.fromContextPath(request)
.path("/accounts").build()
URI uri = ServletUriComponentsBuilder.fromContextPath(request)
.path("/accounts")
.build()
.toUri();
----
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin
----
// Re-uses host, port and context path...
// Re-uses host, port, scheme and context path...
val ucb = ServletUriComponentsBuilder.fromContextPath(request)
.path("/accounts").build()
val uri = ServletUriComponentsBuilder.fromContextPath(request)
.path("/accounts")
.build()
.toUri()
----
You can create URIs relative to a Servlet (for example, `/main/{asterisk}`),
@ -4152,18 +4154,22 @@ as the following example shows:
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
----
// Re-uses host, port, context path, and Servlet prefix...
// Re-uses host, port, scheme, context path, and Servlet prefix...
ServletUriComponentsBuilder ucb = ServletUriComponentsBuilder.fromServletMapping(request)
.path("/accounts").build()
URI uri = ServletUriComponentsBuilder.fromServletMapping(request)
.path("/accounts")
.build()
.toUri();
----
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin
----
// Re-uses host, port, context path, and Servlet prefix...
// Re-uses host, port, scheme, context path, and Servlet prefix...
val ucb = ServletUriComponentsBuilder.fromServletMapping(request)
.path("/accounts").build()
val uri = ServletUriComponentsBuilder.fromServletMapping(request)
.path("/accounts")
.build()
.toUri()
----
NOTE: As of 5.1, `ServletUriComponentsBuilder` ignores information from the `Forwarded` and