标签:order pat set null use view == false system
一、创建interceptor包,在interceptor中创建一个拦截器并实现HandlerInterceptor
代码:
@Component //拦截逻辑 Object user = request.getSession().getAttribute("loginUser"); |
注意一下:在低版本的SpringBoot中需要实现postHandle方法和afterCompletion方法,高版本的SpringBoot需要用到这两个方法直接重写就行了,在这就不做过多的介绍了。
二、创建一个SpringMvc配置类并实现WebMvcConfigurer类
代码:
@Configuration |
注意:在SpringBoot中,只能通过创建SpringMVC配置文件来注册拦截器,
.addPathPatterns("/**")表示拦截所有的请求,
excludePathPatterns表示路径不需要拦截哪些路径
一定要在这里排除拦截static路径下的静态文件,或者在SpringBoot配置文件上配置,否则页面加载不到样式
标签:order pat set null use view == false system
原文地址:https://www.cnblogs.com/lzhdonald/p/logininterceptor.html