Dowemo
0 0 0 0

Notes used
Called before @ before program execution
@ pointcut

How to use aop ( for example: Login authorization )
1. Add dependencies.

<!--AOP依赖--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-aop</artifactId></dependency>
2. 在包下创建aspect(方面)文件夹
3. 创建相应的class文件 
@Aspect@Component//将文件引入spring容器中publicclassHttpAspect {@Before("execution(public * com.pagedemo.Controller.UserController.userList(..))")
 //加两点的用途是方法中所有的参数全都会被拦截publicvoidlog(){
 System.out.println("1111111111111111111111");
 }
 @After("execution(public * com.pagedemo.Controller.UserController.userList(..))")
 publicvoidafter(){
 System.out.println("22222222222222");
 }
}

There's a duplicate code: Annotation with @ pointcut
Improved after

@Aspect@Component//将文件引入spring容器中publicclassHttpAspect {@Pointcut("execution(public * com.pagedemo.Controller.UserController.userList(..))")
 publicvoidlog(){}
 @Before("log()")
 publicvoiddobefore(){
 System.out.println("11111111111111");
 }
 @After("log()")
 publicvoiddoafter(){
 System.out.println("22222222222222");
 }
}



Copyright © 2011 Dowemo All rights reserved.    Creative Commons   AboutUs