1) 定义Access
@Documented
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME) //设置为运行时可用
public @interface Access {
/**
* @return 此方法不需要登录即可访问
*/
public boolean allowNoLogin();
}
2) 方法标注
@Access(allowNoLogin=true)
protected void login(...){...}
3)调用
Method m=....
if(m.isAnnotationPresent(Access.class)){
Access access=m.getAnnotation(Access.class);
if(!access.allowNoLogin()){
//TODO check login or not
}
}