File upload is one of the common requirements in web development, SPRINGMVC file upload is integrated, it can be easily and quickly developed.
- resolution of multi-part types in SPRINGMVC
When you submit data for enctype= "Multipart/form-data" in a page form , you need to SPRINGMVC parse the data for the multipart type. Configure The multipart type resolver in springmvc.xml .
1 <!--File Upload -2 <BeanID= "Multipartresolver"3 class= "Org.springframework.web.multipart.commons.CommonsMultipartResolver">4 <!--set the maximum size of the uploaded file to 5MB -5 < Propertyname= "Maxuploadsize">6 <value>5242880</value>7 </ Property>8 </Bean>
Edge Resolution internal Use the jar below to upload pictures.
- Create a picture virtual directory store picture
Configure the picture virtual directory on Tomcat and add it under Tomcat under conf/server.xml :
1 < docBase= "F:\develop\upload\temp" path= "/pic" reloadable = "false" />
Access http://localhost:8080/pic to access images under F:\develop\upload\temp.
1 //Product Modification Submission2@RequestMapping ("/edititemsubmit")3 PublicString edititemsubmit (items items, Multipartfile picturefile)throwsexception{4 5 //Original file name6String Picturefile_name =picturefile.getoriginalfilename ();7 //New file name8String NewFileName = Uuid.randomuuid (). toString () +picturefile_name.substring (Picturefile_name.lastindexof ("."));9 Ten //Upload Image OneFile Uploadpic =NewJava.io.File ("f:/develop/upload/temp/" +newfilename); A - if(!uploadpic.exists ()) { - uploadpic.mkdirs (); the } - //write files to disk - Picturefile.transferto (uploadpic); - ... +}
SPRINGMVC Learning--File upload