本节内容:
使用拦截器
在方法前标注自定义注解
拦截所有请求,只处理带有该注解的方法
自定义注解
常用的元注解:
@Target、@Retention、@Document、@Inherited
如何读取注解:
Method.getDeclaredAnnotations ()
Method.getAnnotation (Class annotationClass)
限制用户在未登录前访问到登录后的页面或者普通用户访问到管理员页面。
定义注解
利用注解,统一处理。新建一个annotation包,包下新建一个annotation类。
自定义注解需要用到常见的几个元注解,@Target是作用目标,可以是方法、类等。@Retention是生效时间,运行时有效、编译时有效等。这两个基本时必须写的,@Document文档是否记录,@Inherited是否继承。
package com.neu.langsam.community.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation