码迷,mamicode.com
首页 > 编程语言 > 详细

SpringBoot之过滤器

时间:2019-02-17 00:30:25      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:over   void   boot   chain   import   rri   etc   can   int   

MyFilter1.java

package com.zns.filter;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;

@WebFilter(filterName = "myFilter1", urlPatterns = "/*")
public class MyFilter1 implements Filter {

    @Override
    public void init(FilterConfig config) throws ServletException {
        System.out.println("过滤器初始化");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {
        System.out.println("执行过滤操作");
        chain.doFilter(request, response);
    }

    @Override
    public void destroy() {
        System.out.println("过滤器销毁");
    }
}

 

在启动类增加@ServletComponentScan注解

SpringBoot之过滤器

标签:over   void   boot   chain   import   rri   etc   can   int   

原文地址:https://www.cnblogs.com/zengnansheng/p/10389789.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!