The spring framework implements the file upload function
There are many ways to upload files in Java, such as SmartUpload or strus2. This article shares the use of multipartfile class in spring framework to upload instance files@ H_ 502_ 2@
In this class, two public methods, upload and getfilemap, are defined@ H_ 502_ 2@
The former needs to pass in a map parameter, which is the file list in the form submitted by the user. The final returned value is also a map type object. Its key name is the name of the uploaded file, and the key value is the storage path of the file on the server; The latter is mainly used for testing purposes and is not the main function. The viewer can ignore this method@ H_ 502_ 2@
The controller code uses the fileuploadingutil class defined above to realize the function of file upload@ H_ 502_ 2@
Note: be sure to use POM Add a dependent reference to Commons fileUpload in the XML file, otherwise the code will prompt the error that the fileitemfactory class cannot be found at runtime@ H_ 502_ 2@
Dependency references are as follows@ H_ 502_ 2@
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips@ H_ 502_ 2@