使用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);
}
个人博客原文链接:https://man2.cn/archives/22.html