|
@@ -0,0 +1,31 @@
|
|
|
+package com.lovecoding.jdbc.aop;
|
|
|
+
|
|
|
+import org.aspectj.lang.ProceedingJoinPoint;
|
|
|
+import org.aspectj.lang.Signature;
|
|
|
+import org.aspectj.lang.annotation.Around;
|
|
|
+import org.aspectj.lang.annotation.Aspect;
|
|
|
+import org.aspectj.lang.annotation.Pointcut;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+@Component
|
|
|
+@Aspect
|
|
|
+public class LogsAop {
|
|
|
+
|
|
|
+ @Pointcut("@annotation(com.lovecoding.jdbc.anno.Logs)")
|
|
|
+ public void log(){}
|
|
|
+
|
|
|
+ @Around("log()")
|
|
|
+ public Object aroundLog(ProceedingJoinPoint point){
|
|
|
+ Object proceed = null;
|
|
|
+ Signature signature = point.getSignature();
|
|
|
+ try {
|
|
|
+ //我们在这里就可以记录日志了
|
|
|
+ System.out.println( "[日志] :" + signature.getName() + "方法即将执行" );
|
|
|
+ proceed = point.proceed(point.getArgs());
|
|
|
+ System.out.println( "[日志] :" + signature.getName() + "方法执行结束啦" );
|
|
|
+ } catch (Throwable e) {
|
|
|
+ System.out.println( "[日志] :" + signature.getName() + "执行发生异常" + e.getMessage() );
|
|
|
+ }
|
|
|
+ return proceed;
|
|
|
+ }
|
|
|
+}
|