package com.example.interceptor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; import javax.servlet.*; import java.io.IOException; @Component public class DemoFilter implements Filter { private static final Logger logger = LoggerFactory.getLogger(DemoFilter.class); @Override public void init(FilterConfig filterConfig) throws ServletException { logger.info("=========DemoFilter=======init=============="); } @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { logger.info("=========DemoFilter=======doFilter==start============"); filterChain.doFilter(servletRequest,servletResponse);//执行过滤 logger.info("=========DemoFilter=======doFilter==end============"); } @Override public void destroy() { logger.info("=========DemoFilter=======destroy=============="); } }