Annotation Type RequestPart
@Target(PARAMETER) @Retention(RUNTIME) @Documented public @interface RequestPart
Annotation that can be used to associate the part of a "multipart/form-data" request with a method argument.Supported method argument types include
MultipartFilein conjunction with Spring'sMultipartResolverabstraction,javax.servlet.http.Partin conjunction with Servlet 3.0 multipart requests, or otherwise for any other method argument, the content of the part is passed through anHttpMessageConvertertaking into consideration the 'Content-Type' header of the request part. This is analogous to what @RequestBodydoes to resolve an argument based on the content of a non-multipart regular request.Note that @
RequestParamannotation can also be used to associate the part of a "multipart/form-data" request with a method argument supporting the same method argument types. The main difference is that when the method argument is not a String or rawMultipartFile/Part,@RequestParamrelies on type conversion via a registeredConverterorPropertyEditorwhileRequestPartrelies onHttpMessageConverterstaking into consideration the 'Content-Type' header of the request part.RequestParamis likely to be used with name-value form fields whileRequestPartis likely to be used with parts containing more complex content e.g. JSON, XML).- Since:
- 3.1
- Author:
- Rossen Stoyanchev, Arjen Poutsma, Sam Brannen
- See Also:
RequestParam,RequestMappingHandlerAdapter
required
boolean required
Whether the part is required.Defaults to
true, leading to an exception being thrown if the part is missing in the request. Switch this tofalseif you prefer anullvalue if the part is not present in the request.- Default:
- true