public static interface ServerResponse.BodyBuilder extends ServerResponse.HeadersBuilder<ServerResponse.BodyBuilder>
Modifier and Type | Method and Description |
---|---|
ServerResponse |
body(Object body)
Set the body of the response to the given
Object and return
it. |
<T> ServerResponse |
body(T body,
ParameterizedTypeReference<T> bodyType)
Set the body of the response to the given
Object and return it. |
ServerResponse.BodyBuilder |
contentLength(long contentLength)
Set the length of the body in bytes, as specified by the
Content-Length header. |
ServerResponse.BodyBuilder |
contentType(MediaType contentType)
Set the media type of the body, as specified by the
Content-Type header. |
ServerResponse |
render(String name,
Map<String,?> model)
Render the template with the given
name using the given model . |
ServerResponse |
render(String name,
Object... modelAttributes)
Render the template with the given
name using the given modelAttributes . |
allow, allow, build, build, cacheControl, cookie, cookies, eTag, header, headers, lastModified, lastModified, location, varyBy
ServerResponse.BodyBuilder contentLength(long contentLength)
Content-Length
header.contentLength
- the content lengthHttpHeaders.setContentLength(long)
ServerResponse.BodyBuilder contentType(MediaType contentType)
Content-Type
header.contentType
- the content typeHttpHeaders.setContentType(MediaType)
ServerResponse body(Object body)
Object
and return
it.
Asynchronous response bodies are supported by providing a
CompletionStage
or Publisher
as body (or any
asynchronous producer of a single entity that can be adapted via the
ReactiveAdapterRegistry
).
body
- the body of the response<T> ServerResponse body(T body, ParameterizedTypeReference<T> bodyType)
Object
and return it. The parameter
bodyType
is used to capture the generic type.body
- the body of the responsebodyType
- the type of the body, used to capture the generic typeServerResponse render(String name, Object... modelAttributes)
name
using the given modelAttributes
.
The model attributes are mapped under a
generated name.
Note: Empty Collections
are not added to
the model when using this method because we cannot correctly determine
the true convention name.
name
- the name of the template to be renderedmodelAttributes
- the modelAttributes used to render the templateServerResponse render(String name, Map<String,?> model)
name
using the given model
.name
- the name of the template to be renderedmodel
- the model used to render the template