内容参考自https://my.oschina.net/lichhao/blog/172562
在SpringMVC中,可以使用@RequestBody与@ResponseBody完成报文到对象、对象到报文的转换。这就是依靠Spring3.0引入的消息转换器机制实现的:
HttpMessageConverter
/**
* Strategy interface that specifies a converter that can convert from and to HTTP requests and responses.
*
* @author Arjen Poutsma
* @author Juergen Hoeller
* @since 3.0
* @param <T> the converted object type
*/
public interface HttpMessageConverter<T> {
boolean canRead(Class<?> clazz, @Nullable MediaType mediaType);
boolean canWrite(Class<?> clazz, @Nullable MediaType mediaType);
T read(Class<? extends T> clazz, HttpInputMessage inputMessage)
throws IOException, HttpMessageNotReadableException;
void write(T t, @Nullable MediaType contentType, HttpOutputMessage outputMessage)
throws IOException, Ht