注解声明
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface xxxAnnotation {
/**
* 注解属性
*/
Object xxx() default 5;
}
注解逻辑实现
/**
* @author alpha.
* @className xxxAnnotationExt
* @date 2023/12/7 15:28
*/
@Slf4j
@Aspect
@Component
public class xxxAnnotationExt {
//环绕通知(可以拿到controller请求参数)
@Around("@annotation(com.deju.framework.aspectj.login.LoginExceptionIntercept)")
public Object around(ProceedingJoinPoint pjp) throws Throwable {
xxxAnnotation xxxAnnotation = getAnnotation(pjp);
// 获取HttpServletRequest的参数
参数类型 参数 = (参数类型) pjp.getArgs()[0];
try {
//todo
// 放行原方法调用
Object proceed = pjp.proceed();
//todo
//正常返回
return proceed;
} catch (Exception e) {
// 异常todo
}
}
private xxxAnnotation getAnnotation(ProceedingJoinPoint pjp) {
MethodSignature signature = (MethodSignature) pjp.getSignature();
Method method = signature.getMethod();
Annotation annotation = method.getAnnotation(xxxAnnotation.class);
return (xxxAnnotation) annotation;
}
}
标签:Springboot,Object,annotation,xxxAnnotation,切面,AOP,注解,todo,pjp
From: https://www.cnblogs.com/BoBo-B0BO/p/17883560.html