类 MultipartHttpMessageWriter
- java.lang.Object
- org.springframework.http.codec.LoggingCodecSupport
- org.springframework.http.codec.multipart.MultipartHttpMessageWriter
- 所有已实现的接口:
HttpMessageWriter<MultiValueMap<String,?>>
public class MultipartHttpMessageWriter extends LoggingCodecSupport implements HttpMessageWriter<MultiValueMap<String,?>>
HttpMessageWriter
for writing aMultiValueMap<String, ?>
as multipart form data, i.e."multipart/form-data"
, to the body of a request.The serialization of individual parts is delegated to other writers. By default only
String
andResource
parts are supported but you can configure others through a constructor argument.This writer can be configured with a
FormHttpMessageWriter
to delegate to. It is the preferred way of supporting both form data and multipart data (as opposed to registering each writer separately) so that when theMediaType
is not specified and generics are not present on the target element type, we can inspect the values in the actual map and decide whether to write plain form data (String values only) or otherwise.- 从以下版本开始:
- 5.0
- 作者:
- Sebastien Deleuze, Rossen Stoyanchev
- 另请参阅:
FormHttpMessageWriter
字段概要
字段 修饰符和类型 字段 说明 static Charset
DEFAULT_CHARSET
THe default charset used by the writer.从类继承的字段 org.springframework.http.codec.LoggingCodecSupport
logger
构造器概要
构造器 构造器 说明 MultipartHttpMessageWriter()
Constructor with a default list of part writers (String and Resource).MultipartHttpMessageWriter(List<HttpMessageWriter<?>> partWriters)
Constructor with explicit list of writers for serializing parts.MultipartHttpMessageWriter(List<HttpMessageWriter<?>> partWriters, HttpMessageWriter<MultiValueMap<String,String>> formWriter)
Constructor with explicit list of writers for serializing parts and a writer for plain form data to fall back when no media type is specified and the actual map consists of String values only.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 boolean
canWrite(ResolvableType elementType, MediaType mediaType)
Whether the given object type is supported by this writer.protected byte[]
generateMultipartBoundary()
Generate a multipart boundary.Charset
getCharset()
Return the configured charset for part headers.HttpMessageWriter<MultiValueMap<String,String>>
getFormWriter()
Return the configured form writer.List<HttpMessageWriter<?>>
getPartWriters()
Return the configured part writers.List<MediaType>
getWritableMediaTypes()
Return theMediaType
's that this writer supports.void
setCharset(Charset charset)
Set the character set to use for part headers such as "Content-Disposition" (and its filename parameter).reactor.core.publisher.Mono<Void>
write(org.reactivestreams.Publisher<? extends MultiValueMap<String,?>> inputStream, ResolvableType elementType, MediaType mediaType, ReactiveHttpOutputMessage outputMessage, Map<String,Object> hints)
Write an given stream of object to the output message.从类继承的方法 org.springframework.http.codec.LoggingCodecSupport
isEnableLoggingRequestDetails, setEnableLoggingRequestDetails
从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
从接口继承的方法 org.springframework.http.codec.HttpMessageWriter
write
字段详细资料
DEFAULT_CHARSET
public static final Charset DEFAULT_CHARSET
THe default charset used by the writer.
构造器详细资料
MultipartHttpMessageWriter
public MultipartHttpMessageWriter()
Constructor with a default list of part writers (String and Resource).
MultipartHttpMessageWriter
public MultipartHttpMessageWriter(List<HttpMessageWriter<?>> partWriters)
Constructor with explicit list of writers for serializing parts.
MultipartHttpMessageWriter
public MultipartHttpMessageWriter(List<HttpMessageWriter<?>> partWriters, @Nullable HttpMessageWriter<MultiValueMap<String,String>> formWriter)
Constructor with explicit list of writers for serializing parts and a writer for plain form data to fall back when no media type is specified and the actual map consists of String values only.- 参数:
partWriters
- the writers for serializing partsformWriter
- the fallback writer for form data,null
by default
方法详细资料
getPartWriters
public List<HttpMessageWriter<?>> getPartWriters()
Return the configured part writers.- 从以下版本开始:
- 5.0.7
getFormWriter
@Nullable public HttpMessageWriter<MultiValueMap<String,String>> getFormWriter()
Return the configured form writer.- 从以下版本开始:
- 5.1.13
setCharset
public void setCharset(Charset charset)
Set the character set to use for part headers such as "Content-Disposition" (and its filename parameter).By default this is set to "UTF-8".
getCharset
public Charset getCharset()
Return the configured charset for part headers.
getWritableMediaTypes
public List<MediaType> getWritableMediaTypes()
从接口复制的说明:HttpMessageWriter
Return theMediaType
's that this writer supports.- 指定者:
getWritableMediaTypes
在接口中HttpMessageWriter<MultiValueMap<String,?>>
canWrite
public boolean canWrite(ResolvableType elementType, @Nullable MediaType mediaType)
从接口复制的说明:HttpMessageWriter
Whether the given object type is supported by this writer.- 指定者:
canWrite
在接口中HttpMessageWriter<MultiValueMap<String,?>>
- 参数:
elementType
- the type of object to checkmediaType
- the media type for the write (possiblynull
)- 返回:
true
if writable,false
otherwise
write
public reactor.core.publisher.Mono<Void> write(org.reactivestreams.Publisher<? extends MultiValueMap<String,?>> inputStream, ResolvableType elementType, @Nullable MediaType mediaType, ReactiveHttpOutputMessage outputMessage, Map<String,Object> hints)
从接口复制的说明:HttpMessageWriter
Write an given stream of object to the output message.- 指定者:
write
在接口中HttpMessageWriter<MultiValueMap<String,?>>
- 参数:
inputStream
- the objects to writeelementType
- the type of objects in the stream which must have been previously checked viaHttpMessageWriter.canWrite(ResolvableType, MediaType)
mediaType
- the content type for the write (possiblynull
to indicate that the default content type of the writer must be used)outputMessage
- the message to write tohints
- additional information about how to encode and write- 返回:
- indicates completion or error
generateMultipartBoundary
protected byte[] generateMultipartBoundary()
Generate a multipart boundary.By default delegates to
MimeTypeUtils.generateMultipartBoundary()
.