Spring的自定義註解簡單實現
阿新 • • 發佈:2019-02-14
round 自定義 pre tail img value npoi cut ava
1、註解的示例為在方法入參上加後綴
代碼示例:
@Component @Aspect public class HelloAspect { // 將此類的解析指向註解 @Pointcut("@annotation(com.annotation.annotationImpl.WoToken)") private void cut() { //切點 } @Around("cut()&&@annotation(woToken)") public Object advice(ProceedingJoinPoint joinPoint, WoToken woToken) throws Throwable { // 獲取連接點方法運行時的入參列表 Object[] args = joinPoint.getArgs(); for (int i= 0;i<args.length;i++) { String argValue = (String) args[i]; String s = argValue + woToken.value(); args[i] = s; } //執行 Object proceed = joinPoint.proceed(args); return proceed; } }
代碼示例:https://github.com/Pinshuducha/annotation
參考:https://blog.csdn.net/message_lx/article/details/77652260
參考代碼:
Spring的自定義註解簡單實現