LoginSignup
4
6

More than 5 years have passed since last update.

@RequestPartについて

Posted at

multipart/form-dataでファイルのアップロードを行う時用のアノテーションです。
これまでも@RequestParamでファイルを受け取ることができていましたが、
何が違うのか。
Springのドキュメント-RequestParam(English)にもある通り、


  • @RequestParam は単純なname-valueの値を扱うためのもの

  • @RequestPart   はJSONやXMLなど、より複雑な構造のデータを扱うためのもの


です。ただ、今までできなかったわけではないことは知っての通り。
@RequestParam@RequestBodyを使えば同じことはできますよね。

@RequestPartにしかできないことは、
@RequestPart("meta-data")で送られてくるメタ情報を受け取ることができる、ということ。

他にも違うことができるかもしれませんが、
直近で私が@RequestPartを選ぶ基準は、
メタデータで何かすることがあれば@RequestPartを使う。
としようと思います。

4
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
6