Controller:
//upload pictures
@ RequestMapping (" uploadPic/. Do ")
Public void uploadPic (it request,
@ RequestParam (required=false) MultipartFile PIC) throws IOException {
//upload file path
String path=request. GetSession (). GetServletContext () getRealPath ("/upload/");
//upload file name
The String fileName=PIC. GetOriginalFilename ();
The File filePath=new File (the path and fileName);
//determine whether path exists, if there is no will create a
if(! FilePath. GetParentFile (). The exists ()) {
FilePath. GetParentFile (). The mkdir ();
}
//will upload the file to a target file
PIC. TransferTo (new File (path + File. The separator + fileName));
}
Project:
How to upload the picture path changes for the upload under the webapp directory? Thank you sincerely,
CodePudding user response:
To ask? The building Lord solved