方法一:对象不使用注解

@PostMapping(value = "/subject/syncDocuments")

@ResponseBody

@ApiImplicitParam(paramType = "body", dataType = "Subject", name = "subject", value = "稿件")

public Map syncDocuments(@RequestParam(value = "file", required = true) MultipartFile file,

@RequestParam(value = "type" )Integer type,

Subject subject) //稿件对象

使用Postman测试,直接将subject对象的字段填在key的位置

方法二:对象使用注解@RequestPart

@PostMapping(value = "/subject/syncDocuments")

@ResponseBody

@ApiImplicitParam(paramType = "body", dataType = "Subject", name = "subject", value = "稿件")

public Map syncDocuments(@RequestParam(value = "file", required = true) MultipartFile file,

@RequestParam(value = "type" )Integer type,

@RequestPart Subject subject) //稿件对象

使用Postman测试,将字段包装在subject对象里,使用Content type:application/json的内容类型 注:方法二在开发本地测试执行成功,但是在测试人员机子下不通过,执行报错如下: Content type ‘application/octet-stream’ not supported

{

"timestamp": 1681976364292,

"status": 415,

"error": "Unsupported Media Type",

"message": "Content type 'application/octet-stream' not supported",

"path": "/subject/syncDocuments"

}

原因:未将原始json格式的数据转换为http能够识别的字符串流。 解决方案:测试时,可以把对象放到json文件里,将.json文件上传。(如果是前端,则需要转成json格式) 使用Postman测试通过

文章链接

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: