springtoot过滤器注解方法

 

 启动类加入@ServletComponentScan注解

package com.llf.utils;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

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

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.print("初始化。。。。。。。。。。。。。。。。。。。。。。。。。");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.print("自定义过滤器。。。。。。。。。。。。。。。。。。。");
        filterChain.doFilter(servletRequest,servletResponse);
    }

    @Override
    public void destroy() {
        System.out.print("销毁。。。。。。。。。。。。。。。。。。。。。。。。。");
    }
}

 


posted @ 2020-05-02 17:29  _Lawrence  阅读(568)  评论(0编辑  收藏  举报