zoukankan      html  css  js  c++  java
  • springboot使用过滤器Filter

    先创建过滤器配置类:

    
    
    ## 引入的包部分省略...
    @Configuration
    public class FilterConfig {
          @SuppressWarnings({"rawtypes", "unchecked"})
          @Bean
          public FilterRegistrationBean registFilter() {
               FilterRegistrationBean registration = new FilterRegistrationBean();
               registration.setFilter(this.SzlDemoFiler());
               registration.addUrlPatterns("/demo/*");
               registration.setName("JimmyShan");
               registration.setOrder(1);
               return registration;
          }
    
          @Bean
          public Filter SzlDemoFilter() {
               return new SzlDemoFilter();
          }
    
    }

    然后,我们自定义类实现Filter接口:

    ## 引入的包部分省略...

    public
    class SzlDemoFilter implements Filter { private final static Logger log = LoggerFactory.getLogger(SzlDemoFilter.class); //@Autowired //private DemoService demoService; @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { long start = System.currentTimeMillis(); HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse resp = (HttpServletResponse) response; String methodName = req.getMethod(); log.info("Request method is : " + methodName); String uri = req.getRequestURI(); log.info("Request uri is : " + uri); chain.doFilter(request, response); log.info("Execute filter = " + (System.currentTimeMillis() - start) + " ms"); } }
  • 相关阅读:
    [POJ1743]Musical Theme
    ubuntu qq
    Separate code and data contexts: an architectural approach to virtual text sharing
    Python3发送post请求,自动记住cookie
    python 异步协程
    豆瓣爬虫
    pandas 使用
    房天下爬虫
    计算英文文章词频的两种方法
    LOW版统计词频
  • 原文地址:https://www.cnblogs.com/jimmyshan-study/p/10945104.html
Copyright © 2011-2022 走看看