knife4j的3.0.3版本文件上传不显示上传按钮【已解决】

2024-01-10 12:41:35

使用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

文章来源:https://blog.csdn.net/weixin_44470298/article/details/135498729
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。