1.通过自定义注解完成 每个方法上添加该注解就可以使用该切面
//定义切点,注解作为切入点
@Pointcut("@annotation(com.xxxx.Log)")
public void selfRecordsPoinCut() {
}
@Before("selfRecordsPoinCut()")
public void before(){
log.info("before................通知");
}
@After("selfRecordsPoinCut()")
public void after(){
log.info("After................通知");
}
@AfterReturning("selfRecordsPoinCut()")
public void afterReturning(){
log.info("AfterReturning................通知");
}
@AfterThrowing("selfRecordsPoinCut()")
public void afterThrowing(){
log.info("AfterThrowing................通知");
}
@Around("selfRecordsPoinCut()")
public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
log.info("Around................通知");
log.info("进入Around通知....");
return joinPoint.proceed();
}
2.通过execution表达式的方式主要是在定义切点的时候,通过表达式的方式选取到所需要增强的方法。
/定义切点,注解作为切入点
@Pointcut("execution(public * com.xxx.controller..*.*(..))")
public void viewRecordsPoinCut() {
}



