本文共 1462 字,大约阅读时间需要 4 分钟。
package com.example.mongodemo.config;import lombok.extern.slf4j.Slf4j;import org.aspectj.lang.JoinPoint;import org.aspectj.lang.annotation.Aspect;import org.aspectj.lang.annotation.Before;import org.aspectj.lang.annotation.Pointcut;import org.springframework.stereotype.Component;/** * @Author lyr * @create 2020/3/31 15:25 */@Aspect@Component@Slf4jpublic class AopLogger { @Pointcut(value = "execution(* com.example.mongodemo.mapper..*.*(..))") public void beforeCut(){ } @Before(value = "beforeCut()") public void before(JoinPoint joinPoint) { if (joinPoint==null) { return; } String className = joinPoint.getTarget().getClass().getName(); String methodName = joinPoint.getSignature().getName(); log.info("\r\n\r\nDAO层 运行信息:{} -> {}\r\n\r\n",className,methodName); } @Pointcut(value = "execution(* com.example.mongodemo.service.impl..*.*(..))") public void beforeCut2(){ } @Before(value = "beforeCut2()") public void before2(JoinPoint joinPoint) { if (joinPoint==null) { return; } log.info("-------------------------------------\r\n\r\n"); String className = joinPoint.getTarget().getClass().getName(); String methodName = joinPoint.getSignature().getName(); log.info("\r\nService 层 运行信息:{} -> {}\r\n",className,methodName); log.info("\r\n-------------------------------------------------\r\n"); }}
转载地址:http://xauzi.baihongyu.com/