为了账号安全,请及时绑定邮箱和手机立即绑定

使用这个aop日志处理, 在aspect中能获取,方法传入的入参吗

使用这个aop日志处理, 在aspect中能获取,方法传入的入参吗

正在回答

2 回答

可以啊,joinPoint.getArgs()就可以了(JoinPoint是隐性的传入参数)

0 回复 有任何疑惑可以回复我~
#1

imooc_yjy 提问者

非常感谢!
2018-03-06 回复 有任何疑惑可以回复我~

上代码来得直接:

// 一般,需要记录的信息有:url、method、ip、类方法、参数
@Before("log()")
public void doBefore(JoinPoint joinPoint){
   logger.info("Before");
   ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();       HttpServletRequest request  = attributes.getRequest();
   //url                                                //method
   logger.info("url={}",request.getRequestURL());       logger.info("method={}",request.getMethod());
   //ip                                                //类方法
   logger.info("ip={}",request.getRemoteAddr());        logger.info("class_method={}",joinPoint.getSignature().getDeclaringTypeName()+"."+joinPoint.getSignature().getName());
   //参数
   logger.info("args={}",joinPoint.getArgs());
}

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

使用这个aop日志处理, 在aspect中能获取,方法传入的入参吗

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号