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

前端 未结 1 2129
悲&欢浪女
悲&欢浪女 2021-01-19 06:49

I have following controller method:

@RequestMapping(value = \"/owner/terminals/save\", method = RequestMethod.POST)
public String saveTerminal( @RequestParam         


        
相关标签:
1条回答
  • 2021-01-19 07:43

    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.

    0 讨论(0)
提交回复
热议问题