spring Aop @Around @Before @After的区别说明

编程入门 行业动态 更新时间:2024-10-10 19:17:06

spring Aop @Around @Before @After的<a href=https://www.elefans.com/category/jswz/34/1769972.html style=区别说明"/>

spring Aop @Around @Before @After的区别说明

@Before是在所拦截方法执行之前执行一段逻辑。
@After 是在所拦截方法执行之后执行一段逻辑。
@Around是可以同时在所拦截方法的前后执行一段逻辑。
spring只支持方法连接点

@Aspect
@Component
public class LogIntercept {@Pointcut ( "execution(* com.ncx.controller.*.*(..))" )public void recordLog(){}@Before ( "recordLog()" )public void before() {this .printLog( "已经记录下操作日志@Before 方法执行前" );}@Around ( "recordLog()" )public void around(ProceedingJoinPoint pjp) throws Throwable{this .printLog( "已经记录下操作日志@Around 方法执行前" );pjp.proceed();this .printLog( "已经记录下操作日志@Around 方法执行后" );}@After ( "recordLog()" )public void after() {this .printLog( "已经记录下操作日志@After 方法执行后" );}private void printLog(String str){System.out.println(str);}
}

更多推荐

spring Aop @Around @Before @After的区别说明

本文发布于:2023-11-16 19:30:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1633537.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:区别   spring   Aop

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!