SPRINGMVC, Spring, MyBatis file upload

Source: Internet
Author: User

Learn the file upload download, for the image upload to prepare, feel a century has not played upload download, edge-tapping code side record, please each road great God advice:

Reference: http://blog.csdn.net/wjycgl/article/details/55509480

1:jsp page from form: Here are two mandatory conditions. Must be a post-mode submission. 2: Must have enctype attribute, enctype= "Multipart/form-data"

Introduction of JAR packages in 2:maven Pom.xml

<!--file Upload--

    1. <dependency>   
    2. <groupid< span class= "tag" >>commons-fileupload</groupid >  
    3. < artifactid>commons-fileupload</ artifactid>  
    4. <version>1.3.2 </version>  
    5. </dependency>   

3: Define the Commonsmultipartresolver file parser under Spring's servlet View parser, which is the time to run the project if no fileuload-related jar package is added.

    1. <bean id= "Multipartresolver" class= "Org.springframework.web.multipart.commons.CommonsMultipartResolver" >
      <!--Set the default encoding--
      <property name= "defaultencoding" value= "UTF-8"/>
      <!--upload file maximum size 5m-->
      <property name= "maxuploadsize" value= "5242440"/>
      <!--the maximum size (threshold) allowed for file uploads, below this value, only in memory, exceeding this threshold, generating temporary files on the hard disk--
      <property name= "Maxinmemorysize" value= "4096"/>
      <!--set temporary file save path--
      <property name= "Uploadtempdir" value= "Fileupload/temp"/>
      </bean>

4: Controller class, request processing method parameters must have "Multipartfile file" or "Commonsmultipartfile file", and annotated @requestparam

5://Get file name

String fileName = File.getoriginalfilename ();
Get file type
String FileType = File.getcontenttype ();
Copy to specified location

Return "Success";


It's easier to write than to judge anything, so it can be achieved.

SPRINGMVC, Spring, MyBatis file upload

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.