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、打印结果