首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

springAOP (注脚方式)

2012-08-30 
springAOP (注解方式)package com.zf.aspectimport org.aspectj.lang.JoinPointimport org.aspectj.lang

springAOP (注解方式)

package com.zf.aspect;import org.aspectj.lang.JoinPoint;import org.aspectj.lang.ProceedingJoinPoint;import org.aspectj.lang.annotation.AfterReturning;import org.aspectj.lang.annotation.Around;import org.aspectj.lang.annotation.Aspect;import org.aspectj.lang.annotation.Before;import org.aspectj.lang.annotation.Pointcut;import org.springframework.stereotype.Component;import com.zf.dao.PersonDao;@Component@Aspectpublic class DaoAspect {@Pointcut("execution(* com.zf.dao.PersonDao.*(..))")public void daoPointCut(){};@Before("daoPointCut()")public void beforeDao(JoinPoint joinPoint){PersonDao pd = (PersonDao)joinPoint.getTarget();pd.setMessage("helloWorld");System.out.println();System.out.println("beforeDao...");}@AfterReturning("daoPointCut()")public void afterDao(JoinPoint joinPoint){System.out.println(joinPoint.getTarget() instanceof PersonDao);System.out.println("afaterDao...");}@Around("daoPointCut()")public Object daoAround(ProceedingJoinPoint joinPoint) {          Object[] args = joinPoint.getArgs();          System.out.println("argsLength: " + args.length);        for (Object object : args) {//得到目标对象System.out.println(object + "  -------------------------");}        Object obj = null;          try {              obj = joinPoint.proceed(args);        } catch (Throwable e) {              e.printStackTrace();          }          return obj;      }  }
?java进阶?http://www.javady.com/index.php/category/hign_xingneng

热点排行