使用IDEA开发springboot项目,需求中要提交数据项和文件上传,同时接收实体bean对象和文件,后台Controller接收配置方式:

Controller代码如下:

1 @RequestMapping(value="/comment",method = RequestMethod.POST)
2 public @ResponseBody RetResult saveIndustryComment(HttpServletRequest request,@RequestParam("uploadFile")MultipartFile uploadFile,@RequestBody Comment commentBean){
3 
4 //业务逻辑
5 ....
6 }

 

使用Postman工具测试时报如下异常:org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'multipart/form-data;

springboot框架,文件上传问题===org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'multipart/form-data;

 

 

 

解决方案:去掉@RequestBody注解就可以了

1 @RequestMapping(value="/comment",method = RequestMethod.POST)
2 public @ResponseBody RetResult saveIndustryComment(HttpServletRequest request,@RequestParam("uploadFile")MultipartFile uploadFile,Comment commentBean){
3   //业务逻辑
4 }

 

相关文章:

  • 2021-04-17
  • 2022-12-23
  • 2021-10-28
  • 2021-09-19
  • 2021-08-19
  • 2022-02-04
  • 2021-07-26
猜你喜欢
  • 2022-01-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-29
相关资源
相似解决方案