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、打印结果
标签:filter,void,springboot16,class,----,doFilter,过滤器,servletRequest,public 来源: https://www.cnblogs.com/morehair/p/15272201.html