Failed to convert value of type 'org.springframework.web.multipart.commons.CommonsMultipartFile' to required type

孤街醉人 提交于 2019-12-01 21:21:14
M. Deinum

As I commented you are making things too complex. Change your wrapper to the following (with the appropriate getters and setters).

public class OnlyForImagesFileWrapper {
    @Extensions(imageFormats = {".jpg",".png",".gif",".bmp"}, videoFormats = {})
    private MultipartFile file;
    private String name;
...
}

Then your controller method

@RequestMapping(value = "/owner/terminals/save", method = RequestMethod.POST)
public String saveTerminal( @ModelAttribute @Valid OnlyForImagesFileWrapper wrapper, BindingResult bindingResult ) { ... }

And of course in your configuration make sure you have a MultipartFileResolver configured to properly handle the MultipartFile argument as explained in the reference guide.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!