What is difference between @RequestParam, @RequestBody and @RequestPart?

it2025-01-21  20

Map HTTP request header Content-Type, handle request body.

@RequestParam ← application/x-www-form-urlencoded,

@RequestBody ← application/json,

@RequestPart ← multipart/form-data,


RequestParam (Spring Framework 5.1.9.RELEASE API)

map to query parameters, form data, and parts in multipart requests.

RequestParam is likely to be used with name-value form fields

RequestBody (Spring Framework 5.1.9.RELEASE API)

bound to the body of the web request. The body of the request is passed through an HttpMessageConverter to resolve the method argument depending on the content type of the request. (e.g. JSON, XML)

RequestPart (Spring Framework 5.1.9.RELEASE API)

used to associate the part of a “multipart/form-data” request

RequestPart is likely to be used with parts containing more complex content

HttpMessageConverter (Spring Framework 5.1.9.RELEASE API)

a converter that can convert from and to HTTP requests and responses.

All Known Implementing Classes: …, AbstractJsonHttpMessageConverter, AbstractXmlHttpMessageConverter, …

最新回复(0)