@ReponseBody不支持form-data,所以要接收带有文件的form-data有3种方式。
方式一:
@PostMapping("upload")
public String upload(MultipartFile file, String username, String password) {
}
方式二(前端要把其他参数打包成json字符串)
@PostMapping("upload")
public String upload(MultipartFile file, User json) {
}
public class User {
private String username;
private String password
}
方式三
@PostMapping("upload")
public String upload(FileDto fileDto) {
}
public class FileDto {
private MultipartFile file;
private String username;
private String password
}
错误写法(@RequestBody不支持form-data,这种写法接收不到参数)
@PostMapping("upload")
public String upload(@RequestBody FileDto fileDto) {
}