springboot16-filter过滤器----注解方式

1、定义过滤器

@WebFilter(urlPatterns = "/myfilter")  //过滤路径
public class MyFilter implements Filter {

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("------进入过滤器-----");

        filterChain.doFilter(servletRequest, servletResponse);
    }
}

2、启动类添加注解

@SpringBootApplication
@ServletComponentScan(basePackages = "com.study.springboot.filter")
public class Springboot13Filter1Application {

    public static void main(String[] args) {
        SpringApplication.run(Springboot13Filter1Application.class, args);
    }

}

3、打印结果

posted @ 2021-09-15 14:51  不是孩子了  阅读(303)  评论(0)    收藏  举报