zoukankan      html  css  js  c++  java
  • 从aop中获取被拦截方法中的参数

    @Aspect
    public class CacheManager {

    }


    @Before("execution(* com.aliexpress.social.game.cointree.cointree.gateway.application.*.*(..))")
    public void migrateCheck(JoinPoint joinPoint) {
    String userId = getUserIdFromAop(jointPoint);
    }

    //从拦截的参数中获取用户id
    private String getUserIdFromAop(JoinPoint joinPoint){
    //https://www.cnblogs.com/yln20170705/p/10511743.html

    //类名
    String clazzName = joinPoint.getTarget().getClass().getName();
    MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
    //方法名
    String methodName = methodSignature.getName();
    //参数名数组
    String[] parameters = methodSignature.getParameterNames();
    //参数值
    Object[] args = joinPoint.getArgs();

    //获取参数名对应数组下标
    RequestInfoDTO infoDTO = null;
    String userId = null;

    //infoDTO是被拦截的发方法的参数名,例如:plant(RequestInfoDTO infoDTO,Long cropId)
    int paramIndex = ArrayUtils.indexOf(parameters,"infoDTO");
    if (paramIndex != -1){
    //参数info在方法列表中,位于第一个位置
    infoDTO = (RequestInfoDTO)args[0];
    userId = infoDTO.getUserId();

    }
    log.info("getUserIdFromAop clazzName = {} methodName = {} parameters = {} args = {} userId = {} ",
    new Object[] {clazzName, methodName, JSON.toJSONString(parameters), JSON.toJSONString(args), userId});

    return userId;

    }

  • 相关阅读:
    busybox 注意事项
    Implicit vs Explicit Sharing
    Font Creator Program 字库修改合并软件
    Iperf 源代码分析(四)
    QML 中文支持
    file operation
    MFC异常 与C++标准异常
    统一建模语言(UML) 版本 2.0
    MultiByteToWideChar和WideCharToMultiByte用法详解
    UML 基础: 类图
  • 原文地址:https://www.cnblogs.com/ctaixw/p/13210571.html
Copyright © 2011-2022 走看看