0
点赞
收藏
分享

微信扫一扫

aop 中 @Around(“execution(?)“)中路径的配置

//环绕通知    首先是:包名  然后是: 类名  然后是方法名:方法名   括号内是:参数
	@Around("execution(* com.sinosoft.*.controller.*.*(..))")
	public Object around(ProceedingJoinPoint point) throws Throwable{ //参数是目标方法
  try {
  	String typeName="";
  	String locat="";
  	Signature signature = point.getSignature();
  	MethodSignature methodSignature = (MethodSignature)signature;
  	//获取当前执行的方法
  	Method targetMethod = methodSignature.getMethod();
  	
  	//判断是否具有RequestMapping注解
  	UserExtend eUser = (UserExtend) request.getSession().getAttribute("CURRENT_USER_INFO");	
  	if (targetMethod.isAnnotationPresent(LogAnno.class)) {
    typeName=targetMethod.getAnnotation(LogAnno.class).operationType();
    locat=targetMethod.getAnnotation(LogAnno.class).operationName();
    Logger logger=new Logger();
    logger.setCreateTime(new Date());
    logger.setUserid(eUser.getId());
    logger.setOrgid(eUser.getOrgid());
    logger.setOpType(typeName);
    logger.setLocation(locat);
    loggerMapper.insertSelective(logger);
    
  	}
  } catch (Exception e) {
  	e.printStackTrace();
  }
  return point.proceed(); //代理方法的返回值
	}

举报

相关推荐

0 条评论