package com.itheima.aop; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.*; import org.springframework.stereotype.Component; @Slf4j @Aspect @Component public class Myaspect { @Pointcut("execution(* com.itheima.service.impl.DeptServiceImpl.*(..))") public void pt(){} @Around("pt()") public Object ar(ProceedingJoinPoint joinPoint) throws Throwable { log.info("Around before开始执行。。。。"); long start = System.currentTimeMillis(); Object result = joinPoint.proceed(); log.info("Around after开始执行。。。。"); long end= System.currentTimeMillis(); log.info(joinPoint.getSignature()+"方法消耗时间为:{}",(end-start)+"ms"); return result; } @Before("pt()") public void before(){ log.info("before开始执行。。。。"); } @After("pt()") public void after(){ log.info("after开始执行。。。。"); } @AfterReturning("pt()") public void afterreturning(){ log.info("afterreturning开始执行。。。。"); } @AfterThrowing("pt()") public void afterthrowing(){ log.info("afterthrowing开始执行。。。。"); } }