博客
关于我
拦截器使用 所有请求 都判断一下
阅读量:316 次
发布时间:2019-03-04

本文共 1018 字,大约阅读时间需要 3 分钟。

@Componentpublic class WendaWebConfiguration extends WebMvcConfigurerAdapter {    @Autowired    private LoginFilter loginFilter;    @Override    public void addInterceptors(InterceptorRegistry registry) {        registry.addInterceptor(loginFilter);        super.addInterceptors(registry);    }}
@Componentpublic class LoginFilter extends HandlerInterceptorAdapter {    @Override    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {        System.out.println("我是拦截器");        return true;    }}

以上代码片段展示了两个技术类的实现:

  • WendaWebConfiguration类继承自WebMvcConfigurerAdapter,用于配置Spring Boot的Web应用程序的全局拦截器

  • LoginFilter类实现了HandlerInterceptorAdapter接口,作为请求处理的拦截器

  • 代码中使用了@Component注解标记组件,使用了@Autowired注解实现自动注入功能。WendaWebConfiguration类中添加了拦截器的实现,通过registry.addInterceptor(loginFilter)将LoginFilter拦截器注册到拦截器注册表中,同时调用了super.addInterceptors(registry)以继承父类的拦截器配置。LoginFilter类实现了preHandle方法,打印了一条日志信息并返回true,表示该拦截器对请求进行了处理。

    代码结构清晰,注解使用规范,类之间继承关系明确,符合Spring Boot框架的开发规范。

    转载地址:http://pijq.baihongyu.com/

    你可能感兴趣的文章
    POJ 2403
    查看>>
    poj 2406 还是KMP的简单应用
    查看>>
    POJ 2431 Expedition 优先队列
    查看>>
    Qt笔记——获取位置信息的相关函数
    查看>>
    POJ 2484 A Funny Game(神题!)
    查看>>
    POJ 2486 树形dp
    查看>>
    POJ 2488:A Knight's Journey
    查看>>
    SpringBoot为什么易学难精?
    查看>>
    poj 2545 Hamming Problem
    查看>>
    poj 2723
    查看>>
    poj 2763 Housewife Wind
    查看>>
    Qt笔记——模型/视图MVD 文件目录浏览器软件
    查看>>
    POJ 2892 Tunnel Warfare(树状数组+二分)
    查看>>
    poj 2965 The Pilots Brothers' refrigerator-1
    查看>>
    poj 3026( Borg Maze BFS + Prim)
    查看>>
    POJ 3041 - 最大二分匹配
    查看>>
    POJ 3041 Asteroids(二分匹配模板题)
    查看>>
    Qt笔记——标准文件对话框QFileDialog
    查看>>
    poj 3083 Children of the Candy Corn
    查看>>
    POJ 3083 Children of the Candy Corn 解题报告
    查看>>