• spring aop 实现controller 日志


    @Aspect
    @Component
    @Slf4j
    public class ControllerAspact {
    
        @Pointcut("execution(public * com.example.controller..*.*(..))")
        public void requestLog() {
        }
    
        @Before("requestLog()")
        public void doBefore(JoinPoint joinPoint) {
            if (log.isDebugEnabled()) {
                ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
                HttpServletRequest request = attributes.getRequest();
                log.debug("url={}", request.getRequestURL());
                log.debug("method={}", request.getMethod());
                log.debug("class_method={}", joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
                log.debug("args={}", Arrays.toString(joinPoint.getArgs()));
            }
        }
    
        @AfterReturning(returning = "object", pointcut = "requestLog()")
        public void doAfterReturning(Object object) {
            log.info("response={}", object == null ? null : object.toString());
        }
    }
    
    
  • 相关阅读:
    LCM与GCD算法
    LCS,LIS,LICS算法
    高精度算法(C/C++)
    SystemTap
    VMware15下解决Ubuntu18.04没有网络连接问题
    Git ssh-key 配置问题
    Ubuntu18.04更换国内源
    sql 错误日志存储路径设置
    资源
    System.Data.DataTable 基本方法
  • 原文地址:https://www.cnblogs.com/wilwei/p/10244703.html
Copyright © 2020-2023  润新知