Spring MVC- Part IV study concluded (3) file upload, download

1, file upload.

     Spring MVC form in the form of data type must be multipart / form-data type. File using the file form receiving MultipartFile form submission processing method as a parameter. MultipartFile method offers are:

     

   spring MVC default context is not equipped MultipartResolver, it is to be used to upload asking price operation, you need to register MultipartResolver in the configuration file.

<! - File Upload configuration -> 
     < the bean ID = "the MultipartResolver"   
        class = "org.springframework.web.multipart.commons.CommonsMultipartResolver" >   
        <! - upload limit size, in bytes (10MB) - -> 
        < property name = "maxUploadSize" >   
            < value > 10485760 </ value >   
        </ property >   
        <-! coding format requested, must coincide jSP pageEncoding properties, in order to read the contents of the correct form, default ISO -8859-1 -> 
        < Property name = "defaultEncoding" > 
            <value>UTF-8</value>
        </property>
    </bean>

  In addition, the components required Apache Commons FileUpload will commons-fileupload-1.3.3.jar, commons-io-2.6.jar copied to the project lib.

2, file downloads.

   ResponseEntity

3, interceptors

   Interceptor Interceptor. Used to verify user permissions determine whether the user has logged in. Interceptor Spring MVC interceptor intercepts the request is completed by the interface HandlerInterceptor. spring MVC defined Interceptor interceptor is very simple, only need to implement HandlerInterceptor interface, or inherit the abstract class HandlerInterceptorAdapter.

   HandlerInterceptor interface defines three methods:

   

     

 

Guess you like

Origin www.cnblogs.com/ZeroMZ/p/11411848.html