万隆的笔记 万隆的笔记
博文索引
笔试面试
  • 在线学站

    • 菜鸟教程 (opens new window)
    • 入门教程 (opens new window)
    • Coursera (opens new window)
  • 在线文档

    • w3school (opens new window)
    • Bootstrap (opens new window)
    • Vue (opens new window)
    • 阿里开发者藏经阁 (opens new window)
  • 在线工具

    • tool 工具集 (opens new window)
    • bejson 工具集 (opens new window)
    • 文档转换 (opens new window)
  • 更多在线资源
  • Changlog
  • Aboutme
GitHub (opens new window)
博文索引
笔试面试
  • 在线学站

    • 菜鸟教程 (opens new window)
    • 入门教程 (opens new window)
    • Coursera (opens new window)
  • 在线文档

    • w3school (opens new window)
    • Bootstrap (opens new window)
    • Vue (opens new window)
    • 阿里开发者藏经阁 (opens new window)
  • 在线工具

    • tool 工具集 (opens new window)
    • bejson 工具集 (opens new window)
    • 文档转换 (opens new window)
  • 更多在线资源
  • Changlog
  • Aboutme
GitHub (opens new window)
  • Spring

  • SprinvMVC

  • SpringBoot

    • Spring Boot 简介
    • Hello Spring Boot
    • Spring Boot 常用配置
    • YAML 配置文件语言
    • 为什么说 JSON 不适合做配置文件?
    • Spring Boot 整合 Thymeleaf
    • Thymeleaf 常用语法
    • Thymeleaf 表达式语法
    • Thymeleaf 内置对象
    • Spring Boot 整合 Druid
    • Spring Boot 整合 HikariCP
    • Spring Boot 整合 tk.mybatis & PageHelper
    • MyBatis 生成代码 Maven插件
    • Spring Boot 配置拦截器
      • 定义拦截器
      • 配置拦截器
  • Spring
  • SpringBoot
2022-01-15
目录

Spring Boot 配置拦截器

# Spring Boot 配置拦截器

# 定义拦截器

public class MyInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        return false;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {

    }
  
}

# 配置拦截器

注意,要让配置能被Spring扫描到

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
  
    @Bean
    MyInterceptor myInterceptor(){
        return new MyInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(myInterceptor())
          .addPathPatterns("/**")
          .excludePathPatterns("/static");
    }

}
上次更新: 5/30/2023, 12:51:40 AM
最近更新
01
2025
01-15
02
Elasticsearch面试题
07-17
03
Elasticsearch进阶
07-16
更多文章>
Theme by Vdoing
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式