<- 依赖 !->
      <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-aop</artifactId>
        </dependency>


 

@Aspect
@Component
public class TimeAspect {

    private  static Logger logger = LoggerFactory.getLogger(TimeAspect.class);
    @Around("execution(* com.sea.xx.controller.*.*(..))")
    public Object handleAroundControllerMethod(ProceedingJoinPoint pjp) throws Throwable {
        long start = System.currentTimeMillis();
        ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = sra.getRequest();
        String method = request.getMethod();
        String className = pjp.getTarget().getClass().getSimpleName();
        String methodName = pjp.getSignature().getName();
        Object[] args = pjp.getArgs();
        if("GET".equalsIgnoreCase(method)){
            logger.info("^^^^ enter {}.{} receive data with : {} ^^^^", className,methodName,args);
        }else
        {
            logger.info("enter {}.{}", className,methodName);
//            logger.info("enter {}.{} receive data with : {}", className,methodName,args);
        }
        Object object = pjp.proceed();
        String costTime = (System.currentTimeMillis() - start) + "";
        logger.info("^^^^^ end  run the method --> {} total cost time is {} ms ^^^^^", methodName, costTime);
        return object;
    }
}

 

posted on 2019-03-07 17:48  lshan  阅读(453)  评论(0编辑  收藏  举报