java 自定义切面

package com.yiautos.psf.order.util.myannotation;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springblade.core.tool.utils.Func;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class MyLogCreateAspect {
    private static final Logger log = LoggerFactory.getLogger(SericalNumCreateAspect.class);

    @Pointcut("@annotation(com.yiautos.psf.order.util.myannotation.MyLogCreate)")
    public void myLogCreateAspect() {
    }

    @AfterReturning(pointcut = "myLogCreateAspect()", returning = "result")
    public void processMyLogCreateAspect(JoinPoint joinPoint, Object result) {
        Object[] args = joinPoint.getArgs();
        log.info("切面结束:{}", Func.toJson(args));
    }

    @Before("myLogCreateAspect()")
    public void begin() {
        log.info("切面开始");
    }
}
package com.yiautos.psf.order.util.myannotation;

import java.lang.annotation.*;

/***
 * 创建日志
 * @return
 * @date 2022-03-14 11:05
 */
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
public @interface MyLogCreate {
}

  

posted @ 2022-03-14 11:49  八英里  阅读(493)  评论(0编辑  收藏  举报