SpringBoot学习笔记之拦截器使用
来源:互联网 发布:微信二级分销系统源码 编辑:程序博客网 时间:2024/05/16 10:28
Springboot 拦截器
1)、创建我们自己的拦截器类并实现 HandlerInterceptor 接口。
public class LiyjInterceptor implements HandlerInterceptor{
@Override
public void afterCompletion(HttpServletRequest arg0,
HttpServletResponse arg1, Object arg2, Exception arg3)
throws Exception {
System.out.println(this.getClass().getName()+ "<------>afterCompletion");
}
@Override
public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1,
Object arg2, ModelAndView arg3) throws Exception {
System.out.println(this.getClass().getName() + "<------>postHandle");
}
@Override
public boolean preHandle(HttpServletRequest arg0, HttpServletResponse arg1,
Object arg2) throws Exception {
System.out.println(this.getClass().getName() + "<------>preHandle");
return true;
}
}
2)、创建一个Java类继承WebMvcConfigurerAdapter,并重写 addInterceptors 方法。 实例化我们自定义的拦截器,然后将对像手动添加到拦截器链中(在addInterceptors方法中添加)。
@Configuration
public class SpringInterceptorRegister extends WebMvcConfigurerAdapter {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new LiyjInterceptor()).addPathPatterns("/**");
registry.addInterceptor(new ShanInterceptor()).addPathPatterns("/freemarker/**");
super.addInterceptors(registry);
}
}
相关源码下载地址:http://download.csdn.net/download/liyuejin/9986140
阅读全文
0 0
- SpringBoot学习笔记之拦截器使用
- springboot学习之拦截器配置
- SpringBoot之拦截器
- springboot使用拦截器
- SpringBoot学习笔记之Servlet使用
- SpringBoot学习笔记之JDBC使用
- SpringBoot学习笔记之profile使用
- SpringBoot之Interceptor拦截器
- SpringBoot拦截器的使用
- SpringBoot拦截器的使用
- struts2学习笔记之拦截器(Interceptor)
- Struts2学习笔记之自定义拦截器
- Struts2学习笔记之自定义拦截器
- struts2学习笔记之拦截器(Interceptor)
- springboot(八)拦截器之验证登录
- SpringBoot之拦截器(E)
- 使用springBoot的拦截器功能介绍
- 在SpringBoot中使用 拦截器
- cpu,内存,磁盘io
- 多线程解决现实中的抢票问题(初级)
- java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file
- 总结
- CTF 这个看起来有点简单!
- SpringBoot学习笔记之拦截器使用
- POJ-1006 Biorhythms (生物节律)
- 算法提高 ADV-155 上帝造题五分钟
- SVN Working copy locked Please execute the 'Cleanup' command.
- 集合-hashCode
- .h头文件和.a静态库文件问题记录
- Vue数组检测
- java元组
- Jni/NDK常见问题