无法处理零件,因为即使在现有的multipartResolver中也未提供多部件配置

use*_*876 8 java multipartform-data spring-mvc

我尝试实现加载照片和String对象.这是我方法的声明.

@RequestMapping(method = RequestMethod.PUT, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public @ResponseBody ResponseEntity<UserWithPhoto> update(@RequestHeader(value="Access-key") String accessKey,
                                         @RequestHeader(value="Secret-key") String secretKey,
                                         @RequestPart("user") String string,
                                         @RequestPart("photo") MultipartFile file) throws Exception
Run Code Online (Sandbox Code Playgroud)

这是我的多部分解析器

<beans:bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    <beans:property name="maxUploadSize" value="10000000" />
 </beans:bean>
Run Code Online (Sandbox Code Playgroud)

而且我不知道为什么会这样

java.lang.IllegalStateException: Unable to process parts as no multi-part configuration has been provided
Run Code Online (Sandbox Code Playgroud)

Ped*_*lez 0

我总是将多部分文件包装在 POJO 中,并提供所需的其他属性:

public class FileUpload {

   private Long id;
   private MultipartFile file;

   // getters and setters
}
Run Code Online (Sandbox Code Playgroud)

在我看来:

<spring:url value="/myEndpoint" var="url_upload"/>
<form:form method="POST" enctype="multipart/form-data" commandName="fileUpload" action="${url_upload}" >

    <form:hidden path="id" />
    <input type="file" name="file" id="inputFile"/>

    <input type="submit" value="Upload" />
</form:form>        
Run Code Online (Sandbox Code Playgroud)

在端点中:

@RequestMapping(value = "/myEndpoint", method = RequestMethod.POST)
public String uploadFile(@ModelAttribute("fileUpload") FileUpload dto, Model uiModel) {
    // Process file
}
Run Code Online (Sandbox Code Playgroud)