• springboot拦截器实现


     
    package webapp.controller;
    
    import com.alibaba.fastjson.JSONObject;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.web.servlet.HandlerInterceptor;
    import org.springframework.web.servlet.ModelAndView;
    import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
    import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import java.util.Arrays;
    
    /**
     * @Author:vic
     * @Date:Created in 15:20 2018/09/16
     * @Description:
     */
    @Configuration
    public class Interceptor implements WebMvcConfigurer {
    
        /**
         * 添加拦截器
         * @param registry
         */
        @Override
        public void addInterceptors(InterceptorRegistry registry) {
            registry.addInterceptor(new SignInterceptor()).excludePathPatterns(Arrays.asList("/js/**"));//避免静态资源被拦截
        }
    
        //自定义拦截器
        class SignInterceptor implements HandlerInterceptor {
    
            @Override
            public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler){
                //拦截逻辑........ TODO
    
            }
    
            @Override
            public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
    
            }
    
            @Override
            public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
    
            }
        }
    }
    
    
    
    
    

      

    文末小福利免费视频资源网站www.sousuohou.com
  • 相关阅读:
    初识 Mysql
    Python之协程
    crm 动态一级二级菜单
    admin 后台操作表格
    crm 权限设计
    crm 公户变私户的问题 班级管理 课程管理 学习记录初始化
    crm 添加用户 编辑用户 公户和私户的展示,公户和私户的转化
    crm 数据展示 和分页思想(一)
    python django(forms组件)
    python Django 中间件介绍
  • 原文地址:https://www.cnblogs.com/vicF/p/8085582.html
Copyright © 2020-2023  润新知