使用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;
解决方案:去掉@RequestBody注解就可以了
1 @RequestMapping(value="/comment",method = RequestMethod.POST) 2 public @ResponseBody RetResult saveIndustryComment(HttpServletRequest request,@RequestParam("uploadFile")MultipartFile uploadFile,Comment commentBean){ 3 //业务逻辑 4 }
springboot框架,文件上传问题===org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'multipart/form-data;
原文地址:https://www.cnblogs.com/front-end-develop/p/12534224.html
时间: 2024-10-10 07:42:46