Java 支持@RequestPart的多种内容类型

Java 支持@RequestPart的多种内容类型,java,spring,spring-boot,spring-mvc,spring-restcontroller,Java,Spring,Spring Boot,Spring Mvc,Spring Restcontroller,我有一个接受多部分/表单数据的控制器。 以下是控制器声明: @PostMapping(produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<String> upload(@RequestPart(value = "data") Data data, @RequestPart(value = "file") MultipartFile file) 是否可以为

我有一个接受多部分/表单数据的控制器。 以下是控制器声明:

 @PostMapping(produces = MediaType.APPLICATION_JSON_VALUE)
   public ResponseEntity<String> upload(@RequestPart(value = "data") Data data, @RequestPart(value = "file") MultipartFile file)

是否可以为data@RequestPart支持text/plain?

输入是否始终是json?或者它可以是一个简单的字符串,比如“hello”?这是可能的,但毫无意义。来自@requestpartjavadoc:“可用于将“多部分/表单数据”请求的部分与方法参数关联的注释。”它设计用于使用content type=multipart。即使您成功地使其与text/plain一起工作,这充其量也会非常混乱。也许您可以在请求映射注释中添加consume和products字段。@GPI每个部分可能有一个可选的“content type”。如果您发送一个原始txt文件,则该部分可能包含同意的内容类型“text/plain”,但我怀疑,这里的问题是,整个(随附)请求以
text/plain
的形式发送,因此Spring控件甚至在查看内容之前就以“非多部分”的形式拒绝了该请求(这就是
HttpMediaTypeNotSupportedException
让我想到的)。发生此错误的原因是请求是一个多部分,其名为
data
的部分属于
text/plain
Exception occurred - org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'text/plain' not supported    at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:225)