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、打印结果
springboot16-filter过滤器----注解方式

上一篇:阿里云域名查询、域名注册、域名实名认证和域名备案全过程


下一篇:SpringBoot使用过滤器