类 BodyInserters
- java.lang.Object
- org.springframework.web.reactive.function.BodyInserters
public abstract class BodyInserters extends Object
Static factory methods forBodyInserterimplementations.- 从以下版本开始:
- 5.0
- 作者:
- Arjen Poutsma, Rossen Stoyanchev, Sebastien Deleuze
嵌套类概要
嵌套类 修饰符和类型 类 说明 static interfaceBodyInserters.FormInserter<T>Extension ofBodyInserterthat allows for adding form data or multipart form data.static interfaceBodyInserters.MultipartInserterExtension ofBodyInserters.FormInserterthat allows for adding asynchronous parts.
构造器概要
构造器 构造器 说明 BodyInserters()
方法概要
所有方法 静态方法 具体方法 已过时的方法 修饰符和类型 方法 说明 static <T> BodyInserter<T,ReactiveHttpOutputMessage>empty()Inserter that does not write.static <T extends org.reactivestreams.Publisher<DataBuffer>>
BodyInserter<T,ReactiveHttpOutputMessage>fromDataBuffers(T publisher)Inserter to write the givenPublisher<DataBuffer>to the body.static BodyInserters.FormInserter<String>fromFormData(String name, String value)Return aBodyInserters.FormInserterto write the given key-value pair as URL-encoded form data.static BodyInserters.FormInserter<String>fromFormData(MultiValueMap<String,String> formData)Return aBodyInserters.FormInserterto write the givenMultiValueMapas URL-encoded form data.static <T,P extends org.reactivestreams.Publisher<T>>
BodyInserters.MultipartInserterfromMultipartAsyncData(String name, P publisher, Class<T> elementClass)Return aBodyInserters.MultipartInserterto write the given asynchronous parts, as multipart data.static <T,P extends org.reactivestreams.Publisher<T>>
BodyInserters.MultipartInserterfromMultipartAsyncData(String name, P publisher, ParameterizedTypeReference<T> typeReference)Variant offromMultipartAsyncData(String, Publisher, Class)that accepts aParameterizedTypeReferencefor the element type, which allows specifying generic type information.static BodyInserters.MultipartInserterfromMultipartData(String name, Object value)Return aBodyInserters.MultipartInserterto write the given parts, as multipart data.static BodyInserters.MultipartInserterfromMultipartData(MultiValueMap<String,?> multipartData)Return aBodyInserters.MultipartInserterto write the givenMultiValueMapas multipart data.static <T> BodyInserter<T,ReactiveHttpOutputMessage>fromObject(T body)已过时。As of Spring Framework 5.2, in favor offromValue(Object)static <T> BodyInserter<T,ReactiveHttpOutputMessage>fromProducer(T producer, Class<?> elementClass)Inserter to write the given producer of value(s) which must be aPublisheror another producer adaptable to aPublisherviaReactiveAdapterRegistry.static <T> BodyInserter<T,ReactiveHttpOutputMessage>fromProducer(T producer, ParameterizedTypeReference<?> elementTypeRef)Inserter to write the given producer of value(s) which must be aPublisheror another producer adaptable to aPublisherviaReactiveAdapterRegistry.static <T,P extends org.reactivestreams.Publisher<T>>
BodyInserter<P,ReactiveHttpOutputMessage>fromPublisher(P publisher, Class<T> elementClass)Inserter to write the givenPublisher.static <T,P extends org.reactivestreams.Publisher<T>>
BodyInserter<P,ReactiveHttpOutputMessage>fromPublisher(P publisher, ParameterizedTypeReference<T> elementTypeRef)Inserter to write the givenPublisher.static <T extends Resource>
BodyInserter<T,ReactiveHttpOutputMessage>fromResource(T resource)Inserter to write the givenResource.static <T,S extends org.reactivestreams.Publisher<ServerSentEvent<T>>>
BodyInserter<S,ServerHttpResponse>fromServerSentEvents(S eventsPublisher)Inserter to write the givenServerSentEventpublisher.static <T> BodyInserter<T,ReactiveHttpOutputMessage>fromValue(T body)Inserter to write the given value.
构造器详细资料
BodyInserters
public BodyInserters()
方法详细资料
empty
public static <T> BodyInserter<T,ReactiveHttpOutputMessage> empty()
Inserter that does not write.- 返回:
- the inserter
fromValue
public static <T> BodyInserter<T,ReactiveHttpOutputMessage> fromValue(T body)
Inserter to write the given value.Alternatively, consider using the
bodyValue(Object)shortcuts onWebClientandServerResponse.- 类型参数:
T- the type of the body- 参数:
body- the value to write- 返回:
- the inserter to write a single value
- 抛出:
IllegalArgumentException- ifbodyis aPublisheror an instance of a type supported byReactiveAdapterRegistry.getSharedInstance(), for whichfromPublisher(Publisher, Class)orfromProducer(Object, Class)should be used.- 另请参阅:
fromPublisher(Publisher, Class),fromProducer(Object, Class)
fromObject
@Deprecated public static <T> BodyInserter<T,ReactiveHttpOutputMessage> fromObject(T body)
已过时。As of Spring Framework 5.2, in favor offromValue(Object)Inserter to write the given object.Alternatively, consider using the
bodyValue(Object)shortcuts onWebClientandServerResponse.- 类型参数:
T- the type of the body- 参数:
body- the body to write to the response- 返回:
- the inserter to write a single object
- 抛出:
IllegalArgumentException- ifbodyis aPublisheror an instance of a type supported byReactiveAdapterRegistry.getSharedInstance(), for whichfromPublisher(Publisher, Class)orfromProducer(Object, Class)should be used.- 另请参阅:
fromPublisher(Publisher, Class),fromProducer(Object, Class)
fromProducer
public static <T> BodyInserter<T,ReactiveHttpOutputMessage> fromProducer(T producer, Class<?> elementClass)
Inserter to write the given producer of value(s) which must be aPublisheror another producer adaptable to aPublisherviaReactiveAdapterRegistry.Alternatively, consider using the
bodyshortcuts onWebClientandServerResponse.- 类型参数:
T- the type of the body- 参数:
producer- the source of body value(s).elementClass- the class of values to be produced- 返回:
- the inserter to write a producer
- 从以下版本开始:
- 5.2
fromProducer
public static <T> BodyInserter<T,ReactiveHttpOutputMessage> fromProducer(T producer, ParameterizedTypeReference<?> elementTypeRef)
Inserter to write the given producer of value(s) which must be aPublisheror another producer adaptable to aPublisherviaReactiveAdapterRegistry.Alternatively, consider using the
bodyshortcuts onWebClientandServerResponse.- 类型参数:
T- the type of the body- 参数:
producer- the source of body value(s).elementTypeRef- the type of values to be produced- 返回:
- the inserter to write a producer
- 从以下版本开始:
- 5.2
fromPublisher
public static <T,P extends org.reactivestreams.Publisher<T>> BodyInserter<P,ReactiveHttpOutputMessage> fromPublisher(P publisher, Class<T> elementClass)
Inserter to write the givenPublisher.Alternatively, consider using the
bodyshortcuts onWebClientandServerResponse.- 类型参数:
T- the type of the elements contained in the publisherP- thePublishertype- 参数:
publisher- the publisher to write withelementClass- the class of elements in the publisher- 返回:
- the inserter to write a
Publisher
fromPublisher
public static <T,P extends org.reactivestreams.Publisher<T>> BodyInserter<P,ReactiveHttpOutputMessage> fromPublisher(P publisher, ParameterizedTypeReference<T> elementTypeRef)
Inserter to write the givenPublisher.Alternatively, consider using the
bodyshortcuts onWebClientandServerResponse.- 类型参数:
T- the type of the elements contained in the publisherP- thePublishertype- 参数:
publisher- the publisher to write withelementTypeRef- the type of elements contained in the publisher- 返回:
- the inserter to write a
Publisher
fromResource
public static <T extends Resource> BodyInserter<T,ReactiveHttpOutputMessage> fromResource(T resource)
Inserter to write the givenResource.If the resource can be resolved to a file, it will be copied using zero-copy.
- 类型参数:
T- the type of theResource- 参数:
resource- the resource to write to the output message- 返回:
- the inserter to write a
Publisher
fromServerSentEvents
public static <T,S extends org.reactivestreams.Publisher<ServerSentEvent<T>>> BodyInserter<S,ServerHttpResponse> fromServerSentEvents(S eventsPublisher)
Inserter to write the givenServerSentEventpublisher.Alternatively, you can provide event data objects via
fromPublisher(Publisher, Class)orfromProducer(Object, Class), and set the "Content-Type" totext/event-stream.- 类型参数:
T- the type of the data elements in theServerSentEvent- 参数:
eventsPublisher- theServerSentEventpublisher to write to the response body- 返回:
- the inserter to write a
ServerSentEventpublisher - 另请参阅:
- Server-Sent Events W3C recommendation
fromFormData
public static BodyInserters.FormInserter<String> fromFormData(MultiValueMap<String,String> formData)
Return aBodyInserters.FormInserterto write the givenMultiValueMapas URL-encoded form data. The returned inserter allows for additional entries to be added viaBodyInserters.FormInserter.with(String, Object).Note that you can also use the
bodyValue(Object)method in the request builders of both theWebClientandWebTestClient. In that case the setting of the request content type is also not required, just be sure the map contains String values only or otherwise it would be interpreted as a multipart request.- 参数:
formData- the form data to write to the output message- 返回:
- the inserter that allows adding more form data
fromFormData
public static BodyInserters.FormInserter<String> fromFormData(String name, String value)
Return aBodyInserters.FormInserterto write the given key-value pair as URL-encoded form data. The returned inserter allows for additional entries to be added viaBodyInserters.FormInserter.with(String, Object).- 参数:
name- the key to add to the formvalue- the value to add to the form- 返回:
- the inserter that allows adding more form data
fromMultipartData
public static BodyInserters.MultipartInserter fromMultipartData(MultiValueMap<String,?> multipartData)
Return aBodyInserters.MultipartInserterto write the givenMultiValueMapas multipart data. Values in the map can be an Object or anHttpEntity.Note that you can also build the multipart data externally with
MultipartBodyBuilder, and pass the resulting map directly to thebodyValue(Object)shortcut method inWebClient.- 参数:
multipartData- the form data to write to the output message- 返回:
- the inserter that allows adding more parts
- 另请参阅:
MultipartBodyBuilder
fromMultipartData
public static BodyInserters.MultipartInserter fromMultipartData(String name, Object value)
Return aBodyInserters.MultipartInserterto write the given parts, as multipart data. Values in the map can be an Object or anHttpEntity.Note that you can also build the multipart data externally with
MultipartBodyBuilder, and pass the resulting map directly to thebodyValue(Object)shortcut method inWebClient.- 参数:
name- the part namevalue- the part value, an Object orHttpEntity- 返回:
- the inserter that allows adding more parts
fromMultipartAsyncData
public static <T,P extends org.reactivestreams.Publisher<T>> BodyInserters.MultipartInserter fromMultipartAsyncData(String name, P publisher, Class<T> elementClass)
Return aBodyInserters.MultipartInserterto write the given asynchronous parts, as multipart data.Note that you can also build the multipart data externally with
MultipartBodyBuilder, and pass the resulting map directly to thebodyValue(Object)shortcut method inWebClient.- 参数:
name- the part namepublisher- the publisher that forms the part valueelementClass- the class contained in thepublisher- 返回:
- the inserter that allows adding more parts
fromMultipartAsyncData
public static <T,P extends org.reactivestreams.Publisher<T>> BodyInserters.MultipartInserter fromMultipartAsyncData(String name, P publisher, ParameterizedTypeReference<T> typeReference)
Variant offromMultipartAsyncData(String, Publisher, Class)that accepts aParameterizedTypeReferencefor the element type, which allows specifying generic type information.Note that you can also build the multipart data externally with
MultipartBodyBuilder, and pass the resulting map directly to thebodyValue(Object)shortcut method inWebClient.- 参数:
name- the part namepublisher- the publisher that forms the part valuetypeReference- the type contained in thepublisher- 返回:
- the inserter that allows adding more parts
fromDataBuffers
public static <T extends org.reactivestreams.Publisher<DataBuffer>> BodyInserter<T,ReactiveHttpOutputMessage> fromDataBuffers(T publisher)
Inserter to write the givenPublisher<DataBuffer>to the body.- 类型参数:
T- the type of the publisher- 参数:
publisher- the data buffer publisher to write- 返回:
- the inserter to write directly to the body
- 另请参阅:
ReactiveHttpOutputMessage.writeWith(Publisher)