Spring Boot 上传文件
一、实体类
public class UploadModel {
private Long userId;
private MultipartFile img1;
private MultipartFile img2;
/* getter setter */
}
二、接收
@RestController
public class UploadController {
@PostMapping("/upload")
public void upload(UploadModel uploadModel) {
/* 上传逻辑 */
}
}
注意事项
- 接收不需要 @RequestBody 或 @RequestParam 等注解
- 测试时 Header 需要设置 Content-Type 为 multipart/form-data