tlias管理系统-springAOP的切入点表达式execution

This commit is contained in:
2025-10-28 14:27:27 +08:00
parent 396a44ebc7
commit 13d23747f8
4 changed files with 38 additions and 3 deletions

View File

@@ -11,7 +11,7 @@ import org.springframework.stereotype.Component;
@Slf4j
@Component
@Order(3)
@Aspect
//@Aspect
public class MyAspect2 {
@Before("execution(* com.inmind.service.impl.DeptServiceImpl.*(..))")

View File

@@ -11,7 +11,7 @@ import org.springframework.stereotype.Component;
@Slf4j
@Component
@Order(2)
@Aspect
//@Aspect
public class MyAspect3 {
@Before("execution(* com.inmind.service.impl.DeptServiceImpl.*(..))")

View File

@@ -11,7 +11,7 @@ import org.springframework.stereotype.Component;
@Slf4j
@Component
@Order(1)
@Aspect
//@Aspect
public class MyAspect4 {
@Before("execution(* com.inmind.service.impl.DeptServiceImpl.*(..))")

View File

@@ -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 ...");
}
}