使用swagger上传文件时,报错 Content type 'multipart/form-data;boundary=----WebKitFormBoundaryRAYPKeHKTYSNdzc1

使用swagger上传文件时,传参包括一个文件类型的数据,和一个对象实体,上传时报错:

"timestamp": 1473349676109,
  "status": 415,
  "error": "Unsupported Media Type",
  "exception": "org.springframework.web.HttpMediaTypeNotSupportedException",
  "message": "Content type 'multipart/form-data;boundary=----WebKitFormBoundaryTVc9eDC2a2elulOx;charset=UTF-8' not supported",
  "path": "/upload"

经过测试,发现是传入的实体参数前加了 @RequestBody注解导致的,将该注解去掉就好了。

@PostMapping(value = "/save")
    @ApiOperation(value = "保存资质证书")
    public ResponseEntity save(@ApiParam(value = "文件") MultipartFile file, @ApiParam(value = "证书实体") SyBaseCert syBaseCert) {

//业务代码
}

 

你可能感兴趣的:(Java)