Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of RequestMappingHandlerAdapter and HttpMessageConverter Assembly in springmvc

Shulou Source: shulou.com Published: 2022-06-03 14:49:29 11月14日 Update

The editor will share with you the example analysis of RequestMappingHandlerAdapter and HttpMessageConverter assembly in springmvc. I hope you will get something after reading this article. Let's discuss it together.

1. DispatcherServlet default assembly RequestMappingHandlerAdapter, and RequestMappingHandlerAdapter default assembly is as follows: HttpMessageConverter

HttpMessageConverter:

2) after adding the jackson jar package, RequestMappingHandlerAdapter

The assembled HttpMessageConverter is as follows:

two。 HttpMessageConverter

1) HttpMessageConverter is a new interface added by Spring3.0, which is responsible for converting request information into an object (type T) and outputting object (type T) as response information.

2) the method defined by the HttpMessageConverter API:

① Boolean canRead (Class clazz,MediaType mediaType): specifies the type of object that the converter can read, that is, whether the converter can convert the request information to an object of type clazz, and specifies that the MIME type is supported (text/html,applaiction/json, etc.)

② Boolean canWrite (Class clazz,MediaType mediaType): specifies whether the converter can write objects of type clazz to the response stream, which supports media types defined in MediaType.

③ List getSupportMediaTypes (): the media type supported by the converter.

④ T read (Class

Tags: Type object information assembly converter media support example analysis at the same time interface article can be output function information flow done method more knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB vpn macOS Docker Microsoft