是否可以将多部分表单的内容捆绑到相应控制器方法中的单个对象中?
即。如何转换方法
@RequestMapping(value = "/mult", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<SomeBean> upload(@RequestBody MultipartFile multipartFile, @RequestParam String param)
进入具有以下签名的方法:
@RequestMapping(value = "/mult", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<SomeBean> upload(@RequestBody MultipartWrapper wrapper)
其中MultipartWrapper
包含multipartFile和附加参数:
public class MultipartWrapper {
private String param;
private MultipartFile multipartFile;
// Getters & Setters
}
答案 0 :(得分:1)
在其他控制器中使用@ModelAttribute:
@RequestMapping(value = "/mult", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<SomeBean> upload(@ModelAttribute("cmd") MultipartWrapper wrapper) {
...
}
@ModelAttribute("cmd")
public MultipartWrapper getWrapper() {
return new MultipartWrapper();
}
public class MultipartWrapper {
private String param;
private MultipartFile multipartFile;
// Getters & Setters
}