JoinPoint加反射加SpringAPO的综合用法

编程入门 行业动态 更新时间:2024-10-28 09:16:31

JoinPoint加<a href=https://www.elefans.com/category/jswz/34/1765951.html style=反射加SpringAPO的综合用法"/>

JoinPoint加反射加SpringAPO的综合用法

 //        前置通知(Before advice)- 在目标方便调用前执行通知//        后置通知(After advice)- 在目标方法完成后执行通知//        返回通知(After returning advice)- 在目标方法执行成功后,调用通知//        异常通知(After throwing advice)- 在目标方法抛出异常后,执行通知//        环绕通知(Around advice)- 在目标方法调用前后均可执行自定义逻辑@Before("@annotation(timeAno)")//我自己定义的注解可以绑定到任何方法是public synchronized void beforeRequestFlat(JoinPoint joinPoint, TimeAno timeAno) throws Exception {
//        Object getTarget();  获取被代理的对象
//        Object getThis();    获取代理对象Object[] args = joinPoint.getArgs();//获取目标方法的参数值for (int i = 0; i < args.length; i++) {System.out.println("第" + (i + 1) + "个参数为:" + args[i]);}System.out.println(joinPoint.getTarget().getClass().getName());Class<?> clazz =joinPoint.getTarget().getClass();try {Field f  = clazz.getDeclaredField("result");//f.setAccessible(true);try {f.set(clazz.newInstance(),"18");} catch (IllegalAccessException e) {e.printStackTrace();} catch (InstantiationException e) {e.printStackTrace();}} catch (NoSuchFieldException e) {e.printStackTrace();}

}

更多推荐

JoinPoint加反射加SpringAPO的综合用法

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

发布评论

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

>www.elefans.com

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