SpringBoot的filter、listener、interceptor、AOP

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

上一篇:java – 拦截对数据库的查询


下一篇:SpringBoot的filter、listener、interceptor、AOP