zoukankan      html  css  js  c++  java
  • SpringBoot 登录拦截功能的实现

    用到 handlerInterceptor;
    1、实现HandlerInterceptor接口或继承实现了HandlerInterceptor的类
    1) 重写 preHanle 方法 实现登录用户的过滤 判断是否已经登陆,未登录跳转到登录页面
    2、
    1)在springmvc.xml文件的mvc拦截器中加上实现HanderInterceptor的类

    <mvc:interceptors>
    	<mvc:interceptor>
            <bean class="interceptor.LoginInterceptor"/>
            <!-- 需要拦截的url-->
    		<mvc:mapping path="/**"/>
    		<!-- 排除以下url -->
    		<mvc:exclude-mapping path="/main/**"/>    
    

    2)新建配置类WebMvcConfigure实现WebMvcConfigurer接口
    这种方法要在启动类里扫描到实现类

    @Configuration
    public class WebMvcConfigure implements WebMvcConfigurer {
    
        public final static String SESSION_KEY = "user";
        
        @Override
        public void addInterceptors(InterceptorRegistry registry) {
            registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/**","/main.html").excludePathPatterns("/main/**");
        }
    
    }
    
  • 相关阅读:
    【动态规划】合唱团
    【动态规划】抄近路
    【动态规划】机器人军团
    【贪心】赶作业
    【贪心】时空定位I
    【贪心】雷达问题
    【贪心】监测点
    【贪心】闭区间问题
    设计与实现
    Hello World
  • 原文地址:https://www.cnblogs.com/ZCWang/p/12924839.html
Copyright © 2011-2022 走看看