某些数据需要只给某个角色的用户展示,所以使用AOP方式最方便了,
1、首先我们维护了这个角色的人员,简易的管理员表:
2、新建一个注解
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface CheckAdmin {
}
3、某些方法不需要验证,建一个跳过检测的注解
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface SkipCheckAdmin {
String authorities() default "跳过检测";
}
4.我们定义一个切面类,来实现方法层面的拦截
@Aspect
@Component
public class CheckAdminAspect {
private static final Logger logger = LoggerFactory.getLogger(CheckAdminAspect.class);
@Autowired
private ManagerServic