使用Swagger调试文件上传的接口时出现:Required request part 'file' is not present
有一种可能是@RequestPart()注解中设置名称和 MultipartFile的命名出现冲突
例如我所遇到的
@ApiOperation(value="师资库导入", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @PostMapping("/teacherResource") public ResponseResult importteacherResource(@ApiParam(value = "文件") @RequestPart(value = "file") MultipartFile multipartFile)
命名出现了冲突所以调试接口时会出现Required request part 'file' is not present;
解决方法是:
public ResponseResult importteacherResource(@ApiParam(value = "文件") @RequestPart(value = "multipartFile") MultipartFile multipartFile) 保持命名一致即可