使用SpringBoot3集成3.0.3版本knife4j之后的文件上传一直不显示上传按钮,经过不断尝试终于解决
这是原来的代码
@PostMapping("/upload") @OptLog(optCode = OptCode.ADD, optDesc = "上传文件") @Operation(summary = "上传文件") public CommonResult<FileInfoUploadVO> uploadFileInfo(@RequestParam(value= "file") MultipartFile file) throws IOException { FileInfoUploadVO uploadVO = fileInfoService.saveFileInfo(file); return CommonResult.buildSuccess(uploadVO); }
解决办法
将file的@RequestParam 更换为 @RequestPart 即可,如下
@PostMapping("/upload")@OptLog(optCode = OptCode.ADD, optDesc = "上传文件")
@Operation(summary = "上传文件")
public CommonResult<FileInfoUploadVO> uploadFileInfo(@RequestPart(value= "file") MultipartFile file) throws IOException {
FileInfoUploadVO uploadVO = fileInfoService.saveFileInfo(file);
return CommonResult.buildSuccess(uploadVO);
}
终于解决啦
我彭邵东觉得很赞