上传文件(包含多文件)"/>
SpringBoot项目中使用MultipartFile来上传文件(包含多文件)
在实际项目中,会有通过前端上传单个文件,甚至多个文件的请求.
本篇博客就会介绍后端如何实现这种类型的接口,以及如何使用postman去调用
文章目录
- 一. SpringBoot项目中使用MultipartFile上传单文件
-
- 1.1 场景一: 上传单个文件,不包含其它参数
-
- 1.1.1 后端实现, 在Controller层添加如下代码
- 1.1.2 postman接口调用
- 1.2 场景二: 上传单个文件,包含其它参数
-
- 1.2.1 java后台代码
- 1.2.2 postman接口调用
- 1.3 场景三: 上传单个文件,包含其它请求实体
-
- 1.3.1 后端实现
- 1.3.2 postman接口调用
- 二. SpringBoot项目中使用MultipartFile上传多文件
-
- 2.1 上传多个文件,不包含其它参数
-
- 2.1.1后端实现
- 2.1.2 postman接口调用
- 2.2 上传多个文件,包含其它参数
-
- 2.2.1 后端接口代码
- 2.2.2 postman接口调用
- 2.3 上传多个文件,包含其它请求体
-
- 2.3.1 后台代码
- 2.3.2 postman接口调用
- 2.4 复杂场景测试,既包含一个文件,也包含多个文件,同时包含参数和请求体
-
- 2.4.1后台代码
- 2.4.2 postman接口调用
一. SpringBoot项目中使用MultipartFile上传单文件
1.1 场景一: 上传单个文件,不包含其它参数
1.1.1 后端实现, 在Controller层添加如下代码
@RestController
@RequestMapping("/test")
public class MultipartFileController {@PostMappingpublic String multipartFileTest(@ApiParam(value = "multipartFile") @RequestParam MultipartFile multipartFile) throws Exception{File file = new File("E:\data\test\testFile");multipartFile.transferTo(file);return file.getAbsolutePath();}
}
上述代码实现的主要功能是,接
更多推荐
SpringBoot项目中使用MultipartFile来上传文件(包含多文件)
发布评论