【踩坑】post提交文件加对象属性的后台写法

一开始后台controller为

   public Object editBannerForm(@RequestParam("imgFile") MultipartFile imgFile,@RequestBody Banner banner) {
        ................
}

前台swagger报错

{
  "timestamp": "2019-02-27T07:31:48.486+0000",
  "status": 415,
  "error": "Unsupported Media Type",
  "message": "Content type 'multipart/form-data;boundary=----WebKitFormBoundaryO55PLgsBWglG2AqA;charset=UTF-8' not supported",
  "path": "/HelpwinAdmin/bannerAdmin/addBannerForm"
}

后来搜了网上的文章 找到这一篇 https://www.cnblogs.com/yueli/p/7552888.html

将后台controller接口删除@RequestBody

   public Object editBannerForm(@RequestParam("imgFile") MultipartFile imgFile,Banner banner) {
        ................
}

最后成功了 踩坑

你可能感兴趣的:(JAVA)