代码如下:

package ch2.test;

import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Aspect; @Aspect
public class Audience { //表演之前:观点手机
@Before("execution(** ch2.test.Performance.perform(..))")
public void silenceCellPhones()
{
System.out.println("silenCellPhones");
} //表演之前:就座
@Before("execution(** ch2.test.Performance.perform(..))")
public void takingSeats()
{
System.out.println("take seats");
} //表演之后:鼓掌
@AfterReturning("excuttion(** ch2.test.Performance.perform(..))")
public void applause()
{
System.out.println("clap clap clap !!!");
} //表演失败:退票
@AfterThrowing("execution(** ch2.test.Performance.perform(..))")
public void demandRefund()
{
System.out.println("demanding a refund");
}
}

  

2.Pointcut

org.aspectj.lang.annotation.Pointcut;

 package ch2.test;

 import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut; @Aspect
public class Audience2 { //定义命名的切点
@Pointcut("execution(** ch2.test.Performance.perform(..))")
public void Performance(){} //表演开始之前:关闭手机
@Before("Performance()")
public void silenCellPhones()
{
System.out.println("silen cell phones");
} //表演开始之前:入座
@Before("Performance()")
public void takingSeats()
{
System.out.println("take seats");
} //表演开始之后:鼓掌
@AfterReturning("Performance()")
public void applause()
{
System.out.println("clap clap clap");
} //表演结束之后:表演失败退票
@AfterThrowing("Performance()")
public void demandRefund()
{
System.out.println("demand refund");
} }

最新文章

  1. [转]Android Binder设计与实现 - 设计篇
  2. ExtJs 学习之开篇(三)Ext.grid.Panel表格中的处理
  3. [py]特殊函数+文件保护
  4. Vi命令:如何删除全部内容?
  5. 【转】关于URL编码/javascript/js url 编码/url的三个js编码函数
  6. img标签src=""和background-image:url();引发两次请求页面bug
  7. 将String类型的XML解析并设置到实体类中
  8. DevExpress LookUpEdit和ComboBoxEdit部分用法
  9. linux_memcached_memcachedb
  10. golang protobuf
  11. c语言-函数的定义及传参
  12. 解密电子书之一:电子墨水(eink)
  13. Silverlight下的Socket通讯
  14. Java--回调接口
  15. LeetCode 381. Insert Delete GetRandom O(1) - Duplicates allowed (插入删除和获得随机数 常数时间 允许重复项)
  16. JavaScript(第二十五天)【事件绑定及深入】
  17. TLS 1.3 VS TLS 1.2,让你明白 TLS 1.3 的强大
  18. WCF系列_WCF如何选择不同的绑定
  19. pytorch bug
  20. Gitlab+Jenkins学习之路(十四)之自动化脚本部署实践

热门文章

  1. getTrim(strMz)-我的JavaScript函数库-mazey.js
  2. 斯坦福大学Andrew Ng - 机器学习笔记(4) -- 机器学习算法的选择与评估
  3. 运行scrapy保存图片,报错ValueError: Missing scheme in request url: h
  4. 修改mysql root的密码
  5. always on 技术
  6. Oracle学习笔记—常用函数
  7. Django of python 中文文档 及debug tool
  8. centos中搭建nginx环境
  9. MySQL数据库(8)_MySQL数据库总结
  10. Python基础(12)_python模块之sys模块、logging模块、序列化json模块、pickle模块、shelve模块