課程
/后端開發
/Java
/Spring Boot進階之Web進階
使用這個aop日志處理, 在aspect中能獲取,方法傳入的入參嗎
2018-02-21
源自:Spring Boot進階之Web進階 2-2
正在回答
可以啊,joinPoint.getArgs()就可以了(JoinPoint是隱性的傳入參數)
imooc_yjy 提問者
上代碼來得直接:
// 一般,需要記錄的信息有: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());}
舉報
《2小時學習Spring Boot》之進階教程,針對Web方面的相關技巧
4 回答AOP日志不打印
2 回答aop獲取不到值
1 回答在service中調用repository.getByOne(id)這個方法爲什麼返回的空值??id的值已正確傳入??同樣的方法在controller裏面就能返回正確值。
3 回答aspect
1 回答使用aop,配置Pointcut有問題
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2018-02-22
可以啊,joinPoint.getArgs()就可以了(JoinPoint是隱性的傳入參數)
2018-02-22
上代碼來得直接:
// 一般,需要記錄的信息有: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());
}