== 步骤 ==
- 创建注解
// 元注解,注解的注解
@Target 标明该注解可以作用的对象,可以是类、方法、成员变量等
@Retention 保留的时间 ,可以保留到编译期,或者运行期等
@Document 对于含有该注解的类 生成文档注释
@Inherit 注解可以继承
// 实例
@Target(ElementType.Method)
@Retention(Plolicy.RUNTIME)
public @interface t{
}
- 把生成的注解作用到方法上
@Requesting(path="/user",method=RequestMethod.POST)
@t
public void getUser(){
}
- 拦截器处理含有该注解的类
class interceptor implement HandlerInterceptor{
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
if (handler instanceof HandlerMethod) {
HandlerMethod handlerMethod = (HandlerMethod) handler;
Method method = handlerMethod.getMethod();
// 获取注解
method.getAnnotation(t.class);
//判断这个访问的路径是否满足要求
}
return true;
}
}










