当前位置: 首页 > news >正文

企业网站设计文档/seo排名关键词搜索结果

企业网站设计文档,seo排名关键词搜索结果,做壮阳药网站,学院网站群建设的目标【返回通知】 LoggingAspect.java: 1 Aspect2 Component3 public class LoggingAspect {4 /*5 * 在方法正常执行后执行的通知叫返回通知6 * 返回通知是可以访问到方法的返回值的7 */8 AfterReturning(value"execution(public int com.h…

【返回通知】

LoggingAspect.java:

 1 @Aspect
 2 @Component
 3 public class LoggingAspect {
 4     /*
 5      * 在方法正常执行后执行的通知叫返回通知
 6      * 返回通知是可以访问到方法的返回值的
 7      */
 8     @AfterReturning(value="execution(public int com.hk.spring.aop.notice.ArithmeticCalculator.*(..))",
 9                     returning="result")
10     public void afterReturning(JoinPoint joinPoint,Object result){
11         String methodName = joinPoint.getSignature().getName();
12         System.out.println("The method " + methodName + " ends with " + result);
13     }
14  
15 }

 

Main.java:

 1 public class Main {
 2 
 3     public static void main(String[] args) {
 4         ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
 5         ArithmeticCalculator arithmeticCalculator = (ArithmeticCalculator) ctx.getBean("ArithmeticCalculator");
 6         
 7         System.out.println(arithmeticCalculator.getClass().getName());
 8         
 9         int result = arithmeticCalculator.add(1, 2);
10         System.out.println("result: " + result);
11         
12         result = arithmeticCalculator.div(1000, 10);
13         System.out.println("result " + result);
14 
15     }
16 
17 }

 

运行结果:

【异常通知】

1.只在连接点抛出异常时才执行异常通知。

2.将Throwing属性添加到@AfterThrowing注解中,也可以访问连接点抛出的异常。Throwable是所有错误和异常类的超类。所以在异常通知方法可以捕获到任何错误和异常。

3.如果只对某种特殊的异常类型感兴趣,可以将参数声明为其他类型的参数类型。然后通知就只在抛出这个类型及其子类的异常时才被执行。

 

LoggingAspect.java:

 1 /*
 2      * 在目标方法出现异常时,会执行代码。
 3      * 可以访问到异常对象;且可以指定在出现特定异常时在执行通知
 4      */
 5     @AfterThrowing(value="execution(public int com.hk.spring.aop.notice.ArithmeticCalculator.*(..))",
 6                    throwing="ex")
 7     public void afterThrowing(JoinPoint joinPoint,Exception ex){
 8         String methodName = joinPoint.getSignature().getName();
 9         System.out.println("The method " + methodName + " coours exception : " + ex);
10     }

 

Main.java:

 1 public class Main {
 2 
 3     public static void main(String[] args) {
 4         ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
 5         ArithmeticCalculator arithmeticCalculator = (ArithmeticCalculator) ctx.getBean("ArithmeticCalculator");
 6         
 7         System.out.println(arithmeticCalculator.getClass().getName());
 8         
 9         int result = arithmeticCalculator.add(1, 2);
10         System.out.println("result: " + result);
11         
12         result = arithmeticCalculator.div(1000, 0);
13         System.out.println("result " + result);
14 
15     }
16 
17 }

 

运行结果:

注:1000/0 发生异常。

 

【环绕通知】

LoggingAspect.java:

 1     /*
 2      * 环绕通知需要携带ProceedingJoinPoint 类型的参数
 3      * 环绕通知类似于动态代理的全过程:ProceedingJoinPoint这个类型的参数可以决定是否执行目标方法
 4      * 且环绕通知必须有返回值,返回值即为目标方法的返回值
 5      */
 6     @Around("execution(public int com.hk.spring.aop.notice.ArithmeticCalculator.*(..))")
 7     public Object aroundMethod(ProceedingJoinPoint pjd){
 8         
 9         Object result = null;
10         String methodName = pjd.getSignature().getName();
11         
12         //执行目标方法
13         try {
14             //前置通知
15             System.out.println("The method " + methodName + "begins with " + Arrays.asList(pjd.getArgs()));
16             result = pjd.proceed();
17             //后置通知
18             System.out.println("The method " + methodName + "ends with " + result);
19         } catch (Throwable e) {
20             //异常通知
21             System.out.println("The method occurs exception:" + e);
22         }
23         //后置通知
24         System.out.println("The method " + methodName + " ends");
25         return result;
26     }

运行结果:

 

假如发生异常:

运行结果:

 

转载于:https://www.cnblogs.com/zhzcode/p/9670720.html

http://www.lbrq.cn/news/1310419.html

相关文章:

  • 巴中网站建设/百度关键词优化企业
  • 怎么把网站的标题做的炫酷/推广公众号
  • 深圳互联网网页设计招聘/丁的老头seo博客
  • 资阳做网站/识图搜索在线 照片识别
  • 青岛产品设计公司/洛阳seo网络推广
  • vue响应式网站开发/色盲色弱测试
  • 州网站建设要找嘉艺网络/引流推广的句子
  • 帝国做的网站打开速度/百度快速排名平台
  • 网站开发网页制作薪资/百度账号注册
  • 企业网站制作的软件/网络营销好找工作吗
  • 灵犀科技网站建设/夸克搜索网页版
  • 购物网站宣传方案/建一个企业网站多少钱
  • 惟博df1042可以看多远/信息流广告优化师培训
  • 十八大禁用黄app软件入口/长沙网站优化效果
  • 受欢迎的大连网站建设/百度网址大全旧版安装
  • 电子商务网站建设实训心得体会/什么是网站推广
  • 湛江制作网站公司/微信指数查询入口
  • 做网站什么系统简单/短期的技能培训有哪些
  • 松桃和兴建设公司网站/360排名检测
  • 做网站的需求调研/怎样建立一个网站
  • 做金馆长网站网站/seo刷排名工具
  • python 如何做网站/百度搜图入口
  • 乌托邦网站建设/济南网站优化排名
  • 世界网站流量排名/最近五天的新闻大事
  • 自己做网站到哪里去接广告/电子商务网站设计方案
  • 辽宁省企业信息系统/seo关键词排名优化联系方式
  • 淮安市政府门户网站建设的调查报告/小红书推广方式
  • 做网站ps能用美图秀秀么/双11销量数据
  • 宁波网站建设制作价格/知名网络推广
  • 做企业网站需要买什么资料/发布会直播平台
  • Python元组(Tuple)指南
  • 【Servo】伺服驱动器扫频功能方案文档
  • Selenium 启动的浏览器自动退出问题分析
  • 模型移植实战:从PyTorch到ONNX完整指南
  • 第六章 OBProxy 路由与使用运维
  • Dify的默认端口怎么修改