zoukankan      html  css  js  c++  java
  • Spring Boot 7.拦截器

    package com.example.springbootstudy;
    
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import org.springframework.web.servlet.HandlerInterceptor;
    import org.springframework.web.servlet.ModelAndView;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    public class UserInterceptor implements HandlerInterceptor {
    
        private static final Logger logger = LoggerFactory.getLogger(UserInterceptor.class);
    
        @Override
        public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
            logger.debug("preHandle");
    //        throw new Exception("preHandle Exception");
            return true;
        }
    
        @Override
        public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
            logger.debug("postHandle");
    //        throw new Exception("postHandle Exception");
        }
    
    
        @Override
        public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
            logger.debug("afterCompletion");
        }
    }
    package com.example.springbootstudy;
    
    import org.springframework.context.annotation.Configuration;
    import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
    import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
    
    @Configuration
    public class AppMvcConfig implements WebMvcConfigurer {
    
        @Override
        public void addInterceptors(InterceptorRegistry registry) {
            registry.addInterceptor(new UserInterceptor()).addPathPatterns("/**");
        }
    }
  • 相关阅读:
    在床上手机看完电影让电脑关机 休眠 golang源码--配合手机ES浏览器开一个FTP
    goland授权
    goland 交叉生成linux文件
    串口2345常出错误记录
    [转]Golang号称高并发,但高并发时性能不高
    gogland如何配置路径,解决找不到相对路径配置文件的问题
    window ssh key访问linux
    Vue.js指令小结
    GIT Introduction
    scrapy 简单介绍
  • 原文地址:https://www.cnblogs.com/hbolin/p/10671694.html
Copyright © 2011-2022 走看看