tlias管理系统-springAOP的切入点表达式execution
This commit is contained in:
@@ -11,7 +11,7 @@ import org.springframework.stereotype.Component;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
@Order(3)
|
@Order(3)
|
||||||
@Aspect
|
//@Aspect
|
||||||
public class MyAspect2 {
|
public class MyAspect2 {
|
||||||
|
|
||||||
@Before("execution(* com.inmind.service.impl.DeptServiceImpl.*(..))")
|
@Before("execution(* com.inmind.service.impl.DeptServiceImpl.*(..))")
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import org.springframework.stereotype.Component;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
@Order(2)
|
@Order(2)
|
||||||
@Aspect
|
//@Aspect
|
||||||
public class MyAspect3 {
|
public class MyAspect3 {
|
||||||
|
|
||||||
@Before("execution(* com.inmind.service.impl.DeptServiceImpl.*(..))")
|
@Before("execution(* com.inmind.service.impl.DeptServiceImpl.*(..))")
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import org.springframework.stereotype.Component;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
@Order(1)
|
@Order(1)
|
||||||
@Aspect
|
//@Aspect
|
||||||
public class MyAspect4 {
|
public class MyAspect4 {
|
||||||
|
|
||||||
@Before("execution(* com.inmind.service.impl.DeptServiceImpl.*(..))")
|
@Before("execution(* com.inmind.service.impl.DeptServiceImpl.*(..))")
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.inmind.aop;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
|
import org.aspectj.lang.annotation.Before;
|
||||||
|
import org.aspectj.lang.annotation.Pointcut;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
//切面类
|
||||||
|
@Slf4j
|
||||||
|
@Aspect
|
||||||
|
@Component
|
||||||
|
public class MyAspect6 {
|
||||||
|
|
||||||
|
//DeptServiceImpl类中的delete方法
|
||||||
|
// @Pointcut("execution(public void com.inmind.service.impl.DeptServiceImpl.delete(java.lang.Integer))")
|
||||||
|
// @Pointcut("execution(void com.inmind.service.impl.DeptServiceImpl.delete(java.lang.Integer))")//省略访问修饰符public
|
||||||
|
// @Pointcut("execution(void delete(java.lang.Integer))")//省略访问修饰符public 和包名,类名,但是不建议省略包名和类名,匹配范围过大,匹配多次delete方法
|
||||||
|
// @Pointcut("execution(void com.inmind.service.DeptService.delete(java.lang.Integer))")//省略访问修饰符public,基于接口来写切入点表达式
|
||||||
|
// @Pointcut("execution(void com.inmind.service.DeptService.*(java.lang.Integer))")//省略访问修饰符public,基于接口来写切入点表达式
|
||||||
|
// @Pointcut("execution(* com.inmind.service.DeptService.*(..))")//匹配DeptService接口下的所有的方法(最常见的编写方式)
|
||||||
|
// @Pointcut("execution(* com.*.service.*.delete*(..))")//*可以匹配包,类,方法名,和它们的一部分
|
||||||
|
|
||||||
|
/*接下来有个小需求:需要匹配list和delete这2个方法,它们名称上没有相同的地方,参数列表也不同,一个有返回值,一个没返回值,
|
||||||
|
那怎么用一个切入点表达式表示呢??*/
|
||||||
|
|
||||||
|
@Pointcut("execution(* com.inmind.service.DeptService.list())||execution(* com.inmind.service.DeptService.delete(java.lang.Integer))")
|
||||||
|
private void pt(){}
|
||||||
|
|
||||||
|
@Before("pt()")
|
||||||
|
public void before(){
|
||||||
|
log.info("MyAspect6 ... before ...");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user