@PostMapping(“/upload”)
public void fileUpload2(@RequestParam(“file”) CommonsMultipartFile file, HttpServletRequest request) throws IOException {
System.out.println(“走了”);
//上传路径保存设置
String path=request.getServletContext().getRealPath(“/upload”);
File realPath=new File(path);
if (!realPath.exists()) {
realPath.mkdir();
}
//上传文件地址
System.out.println(“上传文件保存地址:” + realPath);
@PostMapping(“/upload”)
public void fileUpload2(@RequestParam(“file”) CommonsMultipartFile file, HttpServletRequest request) throws IOException {
System.out.println(“走了”);
//上传路径保存设置
String path=request.getServletContext().getRealPath(“/upload”);
File realPath=new File(path);
if (!realPath.exists()) {
realPath.mkdir();
}
//上传文件地址
System.out.println(“上传文件保存地址:” + realPath);
//通过CommonsMultipartFile的方法直接写文件(注意这个时候)
file.transferTo(new File(realPath + “/” + file.getOriginalFilename()));
}
© 版权声明
文章版权归作者所有,未经允许请勿转载。