aop 获取方法入参_从aop中获取被拦截方法中的参数

本文介绍了如何在AOP切面中利用JoinPoint获取被拦截方法的参数,特别是如何从中提取用户ID。通过`@Before`注解定义切点,并在`migrateCheck`方法中调用`getUserIdFromAop`,从参数列表中找到特定参数(如RequestInfoDTO),进而获取其中的用户ID。
摘要由CSDN通过智能技术生成

@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;</

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值