1.前置通知:在业务代码执行前执行增强代码
@Before(value = "execution()")
public void doLog(){
System.out.println("time:"+new Date());
}
2.后置通知:在业务代码执行后执行增强代码
@AfterReturning(value = "execution()",returning = "res")
public void doUpdate(Object res){
System.out.println("这是切面的方法"+res);
}
3.环绕通知:在业务代码执行前后都可执行增强代码
@Around(value = "execution(* org.example.service.impl.SomeServiceImpl.doAround(String))")
public Object doLogin(ProceedingJoinPoint joinPoint) throws Throwable {
Object object = null;
Object[] args = joinPoint.getArgs();
if ("zhang".equals(args[0])){
object = joinPoint.proceed();
}else {
object = "登录失败";
}
return object;
}
4.异常通知:在业务代码抛出异常时执行增强代码
5.最终通知:总是会执行,在目标方法后执行