javaEEday12-springAOP-通知类型--2
This commit is contained in:
@@ -10,13 +10,19 @@ import org.springframework.stereotype.Component;
|
||||
@Aspect
|
||||
public class MyAspect1 {
|
||||
|
||||
//相同切入点表达式的抽取(定义切入点)
|
||||
@Pointcut("execution(* com.inmind.service.impl.DeptServiceImpl.*(..))")
|
||||
public void pt(){};//此次可以定义为private私有和public公有,作用是是否开放切入点表达式
|
||||
|
||||
|
||||
//前置通知
|
||||
@Before("execution(* com.inmind.service.impl.DeptServiceImpl.*(..))")
|
||||
// @Before("execution(* com.inmind.service.impl.DeptServiceImpl.*(..))")
|
||||
@Before("pt()")
|
||||
public void before(){
|
||||
log.info("before ...");
|
||||
}
|
||||
|
||||
@Around("execution(* com.inmind.service.impl.DeptServiceImpl.*(..))")
|
||||
@Around("pt()")
|
||||
public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
log.info("around before ...");
|
||||
|
||||
@@ -27,17 +33,17 @@ public class MyAspect1 {
|
||||
return result;
|
||||
}
|
||||
|
||||
@After("execution(* com.inmind.service.impl.DeptServiceImpl.*(..))")
|
||||
@After("pt()")
|
||||
public void after(){
|
||||
log.info("after ...");
|
||||
}
|
||||
|
||||
@AfterReturning("execution(* com.inmind.service.impl.DeptServiceImpl.*(..))")
|
||||
@AfterReturning("pt()")
|
||||
public void afterReturning(){
|
||||
log.info("afterReturning ...");
|
||||
}
|
||||
|
||||
@AfterThrowing("execution(* com.inmind.service.impl.DeptServiceImpl.*(..))")
|
||||
@AfterThrowing("pt()")
|
||||
public void afterThrowing(){
|
||||
log.info("afterThrowing ...");
|
||||
}
|
||||
|
||||
@@ -7,12 +7,13 @@ import org.aspectj.lang.annotation.Aspect;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
//@Aspect//表示当前是AOP类,面向切面生效的
|
||||
@Aspect//表示当前是AOP类,面向切面生效的
|
||||
@Slf4j
|
||||
public class TimeAspect {
|
||||
|
||||
//模版方法
|
||||
@Around("execution(* com.inmind.service.*.*(..))")//切入点表达式(表示com.inmind.service包下的所有类下,所有方法都生效)
|
||||
// @Around("execution(* com.inmind.service.*.*(..))")//切入点表达式(表示com.inmind.service包下的所有类下,所有方法都生效)
|
||||
@Around("com.inmind.aop.MyAspect1.pt()")
|
||||
public Object recordTime(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
//1.记录开始时间
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
@@ -20,6 +20,7 @@ public class DeptServiceImpl implements DeptService {
|
||||
//查询部门列表
|
||||
@Override
|
||||
public List<Dept> deptList() {
|
||||
//int i = 1/0;
|
||||
//调用deptMapper获取部门列表数据
|
||||
List<Dept> deptList = deptMapper.deptList();
|
||||
return deptList;
|
||||
|
||||
Reference in New Issue
Block a user