<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>file测试</title>
</head>
<body>
<form action="/upload" method="post" enctype="multipart/form-data">
<p>
选择文件:<input type="file" name="file">
</p>
<input type="submit" value="提交">
</form>
</body>
</html>
@PostMapping("/upload")
@ResponseBody
public String handleFileLoad(MultipartFile file) throws IOException {
Properties properties = new Properties();
FileInputStream in = new FileInputStream("C:\\mine\\project\\idea_project\\spring\\springboot-1\\src\\main\\resources\\application.properties");
properties.load(in);
String location = properties.getProperty("spring.servlet.multipart.location");
if (!file.isEmpty()){
String fileName = file.getOriginalFilename();
InputStream ins = file.getInputStream();
file.transferTo(Paths.get(location + "//" + fileName));
System.out.println(fileName);
System.out.println(ins);
return "success";
}
return "failure";
}
@GetMapping(value = "/file")
public String file(){
return "test_file";
}