首先,先上代码,方便讲解
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface PrivilegeAnnotation {
boolean check() default false;
}
@Component
@Aspect
public class PrivilegeAspect {
private static final LogUtil logger = LogUtil.getLogger(PrivilegeAspect.class, "erp-report-service");
@Autowired
private RedisTemplate redisTemplate;
@Before("execution(public * com.didichuxing.erp.report.api.controller.hr.*.*(..)) && @annotation(com.didichuxing.erp.report.basic.aop.annotations.PrivilegeAnnotation)")
public void checkPrivilege(JoinPoint joinPoint){
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
PrivilegeAnnotation privilegeAnnotation = signature.getMethod().getAnnotation(PrivilegeAnnotation.class);
if (Objects.isNull(privilegeAnnotation)) {
return;
}
if (privile