AOP切面编程
添加pom依赖
<dependency> <groupId>org.spring work.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId></dependency>编写切面类
/** * @author wsyjlly * @create 2019.06.14 - 17:23 **/@Aspectpublic class LogAspect { @Pointcut("execution(* cn.wsyjlly.controller.*.*(..))") public void pc(){} @Before(value="pc()") public void before(JoinPoint jp){ String name = jp.getSignature().getName(); System.out.println(name+"方法开始执行..."); System.out.println(name+"——————————————————————————————"); } @After(value = "pc()") public void after(JoinPoint jp){ String name = jp.getSignature().getName(); System.out.println(name+"——————————————————————————————"); System.out.println(name+"方法执行结束..."); } @AfterReturning(value = "pc()" , returning = "result") public void afterReturning(JoinPoint jp, result){ String name = jp.getSignature().getName(); System.out.println(name+"方法返回值为:"+result); } @AfterThrowing(value = "pc()" , throwing = "e") public void afterThrowing(JoinPoint jp,Exception e){ String name = jp.getSignature().getName(); System.out.println(name+"方法抛出异常:"+e.getClass().getName()); } @Around("pc()") public around(ProceedingJoinPoint pjp) throws Throwable{ return pjp.proceed(); }}
继续阅读与本文标签相同的文章
上一篇 :
SpringBoot ~ 启动系统任务
下一篇 :
SpringBoot ~ 拦截器
-
阿里云安全是如何做到的,云安全中心可快速掌握ECS安全态势
2026-05-20栏目: 教程
-
SEO怎样寻找客户资源?哪些客户需要SEO?
2026-05-20栏目: 教程
-
《揭秘Angular 2》| 每日读本书
2026-05-20栏目: 教程
-
RPA是为什么这么火?是技术?是生态?还是资本?
2026-05-20栏目: 教程
-
微服务与网关技术(SIA-GateWay)
2026-05-20栏目: 教程
