Annotation 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 MultipartFile in conjunction with jakarta.servlet.http.Part in conjunction with Servlet multipart requests, or otherwise for any other method argument, the content of the part is passed through an HttpMessageConverter taking into consideration the 'Content-Type' header of the request part. This is analogous to what @RequestBody does to resolve an argument based on the content of a non-multipart regular request.

Note that @RequestParam annotation 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 raw MultipartFile / Part, @RequestParam relies on type conversion via a registered Converter or PropertyEditor while RequestPart relies on HttpMessageConverters taking into consideration the 'Content-Type' header of the request part. RequestParam is likely to be used with name-value form fields while RequestPart is likely to be used with parts containing more complex content e.g. JSON, XML).

从以下版本开始:
4.0 2022/3/2 18:20
作者:
Rossen Stoyanchev, Arjen Poutsma, Sam Brannen, Harry Yang
另请参阅:
  • 可选元素概要

    可选元素
    修饰符和类型
    可选元素
    说明
    The name of the part in the "multipart/form-data" request to bind to.
    boolean
    Whether the part is required.
    Alias for name().
  • 元素详细资料

    • value

      @AliasFor(annotation=RequestParam.class, attribute="value") String value
      Alias for name().
      默认值:
      ""
    • name

      @AliasFor(annotation=RequestParam.class, attribute="name") String name
      The name of the part in the "multipart/form-data" request to bind to.
      默认值:
      ""
    • required

      @AliasFor(annotation=RequestParam.class, attribute="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 to false if you prefer a null value if the part is not present in the request.

      默认值:
      true