我尝试创建将Multipart文件和json作为输入参数的函数。我写这样的功能,就是这样:
@RequestMapping(method = RequestMethod.PUT)
public 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{
User user = new ObjectMapper().readValue(string, User.class);
但问题是无法测试。我像这样使用Postman客户端并收到错误org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is java.lang.IllegalStateException: Unable to process parts as no multi-part configuration has been provided
我相信它因为我没有设置邮递员写
答案 0 :(得分:0)
您是否尝试过将MultipartResolver添加到Spring MVC配置中:
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">