|
|
@@ -0,0 +1,21 @@
|
|
|
+package com.njuzr.eaibackend.config;
|
|
|
+
|
|
|
+import org.aspectj.lang.ProceedingJoinPoint;
|
|
|
+import org.aspectj.lang.annotation.Around;
|
|
|
+import org.aspectj.lang.annotation.Aspect;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import com.njuzr.eaibackend.annotation.LogExecutionTime;
|
|
|
+
|
|
|
+
|
|
|
+@Aspect
|
|
|
+@Component
|
|
|
+public class LogAspect {
|
|
|
+ @Around("@annotation(com.njuzr.eaibackend.annotation.LogExecutionTime)")
|
|
|
+ public Object logTime(ProceedingJoinPoint joinPoint) throws Throwable {
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
+ Object result = joinPoint.proceed();
|
|
|
+ long duration = System.currentTimeMillis() - start;
|
|
|
+ System.out.println("方法执行耗时: " + duration + "ms");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+}
|