主要问题在于不同的Annotation的拦截是不同的。 例如method级别的拦截。我们可以通过getMethodAnnotation(Class)的获取annotation。如果没有设置annotation,获取为空。
举个例子:
// 这里判断是否拦截方法
if(!(handler instanceof HandlerMethod)){
return true;
}
HandlerMethod method = (HandlerMethod)handler;
//这里获取了一个Menu的annotation。
Menu sm = method.getMethodAnnotation(Menu.class);
if(sm!=null){ //如果确实设置了Menu的annotation,就会进入此区域。