首先创建自定义注解
/**
* 不需要拦截注解
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface UnAuth {
}
创建好了自定义注解只需要在不需要拦截的请求上加上标注
@UnAuth
然后 需要在拦截器里面添加 我们这段拦截验证
/**
* 判断是否需要拦截
*/
private boolean isNeedFilter(Object handler) {
HandlerMethod handlerMethod = (HandlerMethod) handler;
return handlerMethod.getMethod().getAnnotation(UnAuth.class) == null;
}