1. HttpMessageConverter消息转换器
(1) HttpMessageConverter接口源码:
public interface HttpMessageConverter{boolean canRead(Class>clazz, MediaType mediaType);boolean canWrite(Class>clazz, MediaType mediaType);
ListgetSupportedMediaTypes();
T read(Class extends T>clazz, HttpInputMessage inputMessage)throwsIOException, HttpMessageNotReadableException;voidwrite(T t, MediaType contentType, HttpOutputMessage outputMessage)throwsIOException, HttpMessageNotWritableException;
}
该接口定义了四个方法,分别是读取数据时的 canRead(), read() 和 写入数据时的canWrite(), write()方法。
(2) 在使用 标签配置时,默认配置了RequestMappingHandlerAdapter(注意是RequestMappingHandlerAdapter不是AnnotationMethodHandlerAdapter),并为他配置了一下默认的HttpMessageConverter:
ByteArrayHttpMessageConverter converts byte arrays.
StringHttpMessageConverter converts strings.
ResourceHttpMessageConverter converts to/from org.spri