欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

SpringBoot的filter、listener、interceptor、AOP

程序员文章站 2022-07-15 15:39:01
...

SpringBoot下的Filter

SpringBoot下的Listener

##SpringBoot下的Interceptor

拦截器
需要继承类型HandlerInterceptorAdapter
并在@Configuration配置类型中配置拦截器


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;



public class PermissionInterceptor extends HandlerInterceptorAdapter {

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		return super.preHandle(request, response, handler);
	}
}
	
@Bean
	public PermissionInterceptor permissionInterceptor() {
		return new PermissionInterceptor();
	}

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(permissionInterceptor()) // 权限拦截器
				.addPathPatterns("/**") // 拦截所有
				.excludePathPatterns("/callback/**") // 排除拦截回调
				.excludePathPatterns("/") // 排除拦截默认
				.excludePathPatterns("/css/**") // 排除拦截静态资源
				.excludePathPatterns("/js/**") // 排除拦截静态资源
				.excludePathPatterns("/favicon.ico"); // 排除拦截静态资源
		super.addInterceptors(registry);
	}

SpringBoot下的AOP