切入点表达式-@annotation
- @annotation(注解全类名)切入点表达式,用于匹配标识有特定注解的方法
- 首先创建一个注解类
-
package com.example.tlias.AOP; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) // todo 设置该注解何时生效 @Target(ElementType.METHOD) // todo 设置该注解的作用范围 public @interface MyLog { }
-
- 然后在目标方法上进行注解标注
-
@Override @MyLog public PageBean Page(Integer page, Integer pageSize, String name, Short gender, LocalDate begin, LocalDate end) { // 设置分页参数 PageHelper.startPage(page, pageSize); // 执行正常查询操作 List<Emp> empList = empMapper.list(name, gender, begin, end); Page<Emp> p = (Page<Emp>) empList; // 封装分页结果PageBean PageBean pageBean = new PageBean(p.getTotal(), p.getResult()); return pageBean; }
-
- 最后在AOP类中设置切入点表达式
-
@Before("@annotation(com.example.tlias.AOP.MyLog)") public void before() { log.info("before...."); }
-
- 首先创建一个注解类