1、文件上传。
Spring MVC的form表单数据类型必须是multipart/form-data类型。使用MultipartFile作为处理方法的参数接收form表单提交的file文件。MultipartFile提供的方法有:

spring MVC上下文默认没有装配MultipartResolver,故要使用上传问价操作,还需要在配置文件中注册MultipartResolver。
<!-- 文件上传配置 --> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <!-- 上传文件大小上限,单位为字节(10MB) --> <property name="maxUploadSize"> <value>10485760</value> </property> <!-- 请求的编码格式,必须和jSP的pageEncoding属性一致,以便正确读取表单的内容,默认为ISO-8859-1 --> <property name="defaultEncoding"> <value>UTF-8</value> </property> </bean>
此外,还需要Apache Commons FileUpload的组件,将commons-fileupload-1.3.3.jar、commons-io-2.6.jar复制到项目lib下。

2、文件下载。
ResponseEntity
3、拦截器
Interceptor拦截器。用于用户权限验证,判断用户是否已经登录。Spring MVC中的Interceptor拦截器拦截请求是通过HandlerInterceptor接口完成的。spring MVC中定义Interceptor拦截器非常简单,只需要实现HandlerInterceptor接口,或者继承抽象类HandlerInterceptorAdapter。
HandlerInterceptor接口定义了三个方法:


原文:https://www.cnblogs.com/ZeroMZ/p/11411848.html