接口 ServerResponse.BodyBuilder
- 封闭接口:
- ServerResponse
public static interface ServerResponse.BodyBuilder extends ServerResponse.HeadersBuilder<ServerResponse.BodyBuilder>
Defines a builder that adds a body to the response.
方法概要
所有方法 实例方法 抽象方法 已过时的方法 修饰符和类型 方法 说明 reactor.core.publisher.Mono<ServerResponse>
body(Object producer, Class<?> elementClass)
Variant ofbody(Publisher, Class)
that allows using any producer that can be resolved toPublisher
viaReactiveAdapterRegistry
.reactor.core.publisher.Mono<ServerResponse>
body(Object producer, ParameterizedTypeReference<?> elementTypeRef)
Variant ofbody(Publisher, ParameterizedTypeReference)
that allows using any producer that can be resolved toPublisher
viaReactiveAdapterRegistry
.reactor.core.publisher.Mono<ServerResponse>
body(BodyInserter<?,? super ServerHttpResponse> inserter)
Set the body of the response to the givenBodyInserter
and return it.<T,P extends org.reactivestreams.Publisher<T>>
reactor.core.publisher.Mono<ServerResponse>body(P publisher, Class<T> elementClass)
Set the body from the givenPublisher
.<T,P extends org.reactivestreams.Publisher<T>>
reactor.core.publisher.Mono<ServerResponse>body(P publisher, ParameterizedTypeReference<T> elementTypeRef)
Variant ofbody(Publisher, Class)
that allows using any producer that can be resolved toPublisher
viaReactiveAdapterRegistry
.reactor.core.publisher.Mono<ServerResponse>
bodyValue(Object body)
Set the body of the response to the givenObject
and return it.ServerResponse.BodyBuilder
contentLength(long contentLength)
Set the length of the body in bytes, as specified by theContent-Length
header.ServerResponse.BodyBuilder
contentType(MediaType contentType)
Set the media type of the body, as specified by theContent-Type
header.ServerResponse.BodyBuilder
hint(String key, Object value)
Add a serialization hint likeJackson2CodecSupport.JSON_VIEW_HINT
to customize how the body will be serialized.ServerResponse.BodyBuilder
hints(Consumer<Map<String,Object>> hintsConsumer)
Customize the serialization hints with the given consumer.reactor.core.publisher.Mono<ServerResponse>
render(String name, Object... modelAttributes)
Render the template with the givenname
using the givenmodelAttributes
.reactor.core.publisher.Mono<ServerResponse>
render(String name, Map<String,?> model)
Render the template with the givenname
using the givenmodel
.reactor.core.publisher.Mono<ServerResponse>
syncBody(Object body)
已过时。as of Spring Framework 5.2 in favor ofbodyValue(Object)
从接口继承的方法 org.springframework.web.reactive.function.server.ServerResponse.HeadersBuilder
allow, allow, build, build, build, cacheControl, cookie, cookies, eTag, header, headers, lastModified, lastModified, location, varyBy
方法详细资料
contentLength
ServerResponse.BodyBuilder contentLength(long contentLength)
Set the length of the body in bytes, as specified by theContent-Length
header.- 参数:
contentLength
- the content length- 返回:
- this builder
- 另请参阅:
HttpHeaders.setContentLength(long)
contentType
ServerResponse.BodyBuilder contentType(MediaType contentType)
Set the media type of the body, as specified by theContent-Type
header.- 参数:
contentType
- the content type- 返回:
- this builder
- 另请参阅:
HttpHeaders.setContentType(MediaType)
hint
ServerResponse.BodyBuilder hint(String key, Object value)
Add a serialization hint likeJackson2CodecSupport.JSON_VIEW_HINT
to customize how the body will be serialized.- 参数:
key
- the hint keyvalue
- the hint value
hints
ServerResponse.BodyBuilder hints(Consumer<Map<String,Object>> hintsConsumer)
Customize the serialization hints with the given consumer.- 参数:
hintsConsumer
- a function that consumes the hints- 返回:
- this builder
- 从以下版本开始:
- 5.1.6
bodyValue
reactor.core.publisher.Mono<ServerResponse> bodyValue(Object body)
Set the body of the response to the givenObject
and return it. This is a shortcut for using abody(BodyInserter)
with a value inserter.- 参数:
body
- the body of the response- 返回:
- the built response
- 抛出:
IllegalArgumentException
- ifbody
is aPublisher
or producer known toReactiveAdapterRegistry
- 从以下版本开始:
- 5.2
body
<T,P extends org.reactivestreams.Publisher<T>> reactor.core.publisher.Mono<ServerResponse> body(P publisher, Class<T> elementClass)
- 类型参数:
T
- the type of the elements contained in the publisherP
- the type of thePublisher
- 参数:
publisher
- thePublisher
to write to the responseelementClass
- the type of elements published- 返回:
- the built response
body
<T,P extends org.reactivestreams.Publisher<T>> reactor.core.publisher.Mono<ServerResponse> body(P publisher, ParameterizedTypeReference<T> elementTypeRef)
Variant ofbody(Publisher, Class)
that allows using any producer that can be resolved toPublisher
viaReactiveAdapterRegistry
.- 类型参数:
T
- the type of the elements contained in the publisherP
- the type of thePublisher
- 参数:
publisher
- thePublisher
to use to write the responseelementTypeRef
- the type of elements produced- 返回:
- the built response
body
reactor.core.publisher.Mono<ServerResponse> body(Object producer, Class<?> elementClass)
Variant ofbody(Publisher, Class)
that allows using any producer that can be resolved toPublisher
viaReactiveAdapterRegistry
.- 参数:
producer
- the producer to write to the requestelementClass
- the type of elements produced- 返回:
- the built response
- 从以下版本开始:
- 5.2
body
reactor.core.publisher.Mono<ServerResponse> body(Object producer, ParameterizedTypeReference<?> elementTypeRef)
Variant ofbody(Publisher, ParameterizedTypeReference)
that allows using any producer that can be resolved toPublisher
viaReactiveAdapterRegistry
.- 参数:
producer
- the producer to write to the responseelementTypeRef
- the type of elements produced- 返回:
- the built response
- 从以下版本开始:
- 5.2
body
reactor.core.publisher.Mono<ServerResponse> body(BodyInserter<?,? super ServerHttpResponse> inserter)
Set the body of the response to the givenBodyInserter
and return it.- 参数:
inserter
- theBodyInserter
that writes to the response- 返回:
- the built response
syncBody
@Deprecated reactor.core.publisher.Mono<ServerResponse> syncBody(Object body)
已过时。as of Spring Framework 5.2 in favor ofbodyValue(Object)
Set the response body to the givenObject
and return it. As of 5.2 this method delegates tobodyValue(Object)
.
render
reactor.core.publisher.Mono<ServerResponse> render(String name, Object... modelAttributes)
Render the template with the givenname
using the givenmodelAttributes
. 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 template- 返回:
- the built response
render
reactor.core.publisher.Mono<ServerResponse> render(String name, Map<String,?> model)
Render the template with the givenname
using the givenmodel
.- 参数:
name
- the name of the template to be renderedmodel
- the model used to render the template- 返回:
- the built response