拦截器Interceptor
拦截器的概述
它的主要作用是拦截用户的请求并进行相应的处理
springmvc组件,权限控制
如何创建?
实现HandlerInterceptor
继承HandlerInterceptorAdapter
preHandle
在 目标Handler(方法)执行前 执行
postHandle
在 目标Handler(方法)执行后,视图生成前 执行
afterCompletion
在 目标Handler(方法)执行后,视图生成后 执行
配置
springmvm.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
https://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!--开启扫描-->
<context:component-scan base-package="com.yjxxt.controller"/>
<!--js,css,images静态资源放行-->
<mvc:default-servlet-handler/>
<!--开启注解-->
<mvc:annotation-driven></mvc:annotation-driven>
<!--试图解析器-->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!--前缀-->
<property name="prefix" value="/"></property>
<!--后缀-->
<property name="suffix" value=".jsp"></property>
</bean>
<!--拦截器-->
<!-- <mvc:interceptors>
<bean class="com.yjxxt.interceptors.MyInterceptor01"></bean>
</mvc:interceptors>-->
<!---->
<!-- <mvc:interceptors>
<!–推荐二–>
<mvc:interceptor>
<!–拦截的路径–>
<mvc:mapping path="/**"/>
<!–放行的路径–>
<mvc:exclude-mapping path="js/**"/>
<mvc:exclude-mapping path="css/**"/>
<mvc:exclude-mapping path="images/**"/>
<!–拦截器对象–>
<bean class="com.yjxxt.interceptors.MyInterceptor01"></bean>
</mvc:interceptor>
<mvc:interceptor>
<!–拦截的路径–>
<mvc:mapping path="/**"/>
<!–放行的路径–>
<mvc:exclude-mapping path="js/**"/>
<mvc:exclude-mapping path="css/**"/>
<mvc:exclude-mapping path="images/**"/>
<!–拦截器对象–>
<bean class="com.yjxxt.interceptors.MyInterceptor02"></bean>
</mvc:interceptor>
</mvc:interceptors>-->
<mvc:interceptors>
<mvc:interceptor>
<!--拦截路径-->
<mvc:mapping path="/**"/>
<!--放行路径-->
<mvc:exclude-mapping path="/userInfo/login"/>
<!--目标拦截器对象-->
<bean class="com.yjxxt.interceptors.LoginInterceptor03"></bean>
</mvc:interceptor>
</mvc:interceptors>
作用?权限控制
上传
1.method==post,entype="mulitipart/form-data"
2:上传的解析器
<!--上传解析器-->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!--文件的最大值,-1,根据文件的大小而定,-->
<property name="maxUploadSize" value="104857600"></property>
<!--文件上传的编码集-->
<property name="defaultEncoding" value="utf-8"></property>
<!--
设置文件放入临时文件夹的最大大小限制。
此值是阈值,低于此值,则保存在内存中,如高于此值,则生成硬盘上的临时文件。
-->
<property name="maxInMemorySize" value="4096"></property>
</bean>
</beans>
3:构建Handler方法,MulitipartFile myFile
RestFul URL