1.按照SpringMVC的方式编写一个拦截器:

2.配置一个类   implements WebMvcConfigurer 接口 为该类添加注解@Configuration  (等价于一个spring的xml文件 比如applicationContext.xml) 标注一个配置类,让Springboot扫描到。覆盖其中的方法并添加已经编写好的拦截器

贴段代码:

@Configuration   // 等价于一个spring的xml文件 比如applicationContext.xml
public class WebConfig implements WebMvcConfigurer {
/**
* 添加拦截器
* @param registry
*/
@Override
public void addInterceptors(InterceptorRegistry registry) {
// 拦截器要拦截的路径
String [] pathPatterns = {
"/**"
};
// 拦截器不拦截的路径
String [] excluedPathPatterns = {
"/boot/hello",
"boot/jsp"
};
registry.addInterceptor(new LoginInterceptor()).addPathPatterns(pathPatterns).excludePathPatterns(excluedPathPatterns); //如果项目中有多个拦截器,把上面代码在复制一行,修改参数即可 }
}

  

addPathPatterns(pathPatterns)和excludePathPatterns(excluedPathPatterns)是可变参数,二u过要拦截的路径只有一条,可以直接写路径名字,不用写数组,如
registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/boot/**").excludePathPatterns(/boot/login);

  

最新文章

  1. 纯html页面之间传参
  2. WIN32 窗口封装类实现
  3. C语言位运算详解[转]
  4. js私有共有成员
  5. JZ2440开发笔记(9)——位置无关代码设计【转】
  6. Kernel Bypass & Offload 介绍
  7. 测试linux和window下 jdk最大能使用多大内存
  8. Codeforces 437C The Child and Toy(贪心)
  9. 一些Android经验
  10. linux新建用户登录不了
  11. 关于使用Git的几点小技巧
  12. Visual Studio Code自定义快捷键(eclipse习惯)
  13. java:找出占用CPU资源最多的那个线程
  14. 服务器配置用户信息、ssh免密码登录和防火墙等安全配置
  15. 【English 】20190319
  16. BZOJ 3669 魔法森林
  17. jdbc工具类1.0
  18. Arrow functions and the ‘this’ keyword
  19. JS-几大排序算法(更新中...)
  20. dubbox2.8.4例子教程一

热门文章

  1. spoj687 REPEATS - Repeats (后缀数组+rmq)
  2. Codeforces Round #345 (Div. 1) C. Table Compression (并查集)
  3. Best Reward && Girls' research
  4. - 迷宫问题 POJ - 3984 bfs记录路径并输出最短路径
  5. DNA Sequence POJ - 2778 AC自动机 && 矩阵快速幂
  6. C# 之 dynamic
  7. LSTM - 长短期记忆网络
  8. [Golang]-6 超时处理、非阻塞通道操作、通道的关闭和遍历
  9. MySQL——时间、字符串、时间戳相互转换
  10. bzoj1013球形空间产生器sphere 高斯消元(有系统差的写法