Spring MVC, Upload file with other fields

后端 未结 1 1742
清酒与你
清酒与你 2021-02-05 17:55

I\'m trying to construct method for uploading file with some other form fields.

This is standard Html form with file and some other fields:

相关标签:
1条回答
  • 2021-02-05 18:32

    Your issues occurs cause your body is consumed when binding the values of the first argument, by ommiting the annotation for the dto the framework will instantiated and populate the matching properties from the request values

      @ResponseBody
      public MyDto createProduct(MyDto dto, @RequestParam MultipartFile file) {
    
      }
    

    note also that you can add a file property of the type MultipartFile to your MyDto instance, it will instantiate and bind correctly as well, so just

    @ResponseBody
    public MyDto createProduct(MyDto dto) {
    
    }
    
    0 讨论(0)
提交回复
热议问题