AOP入门程序

AOP是一种编程思想,而spring框架对这种思想进行实现,那我们学习的就是SpringAOP.

AOP是面向切面编程

AOP快速入门:

1.引入AOP依赖

入门程序:

java 复制代码
package com.itheima.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
@Aspect //表示当前为AOP类
@Component
@Slf4j
public class RecordTimeAspect {

    @Around("execution(* com.itheima.service.impl.*.*(..))")
    public Object recordTime(ProceedingJoinPoint pjp) throws Throwable {
        //1.记录方法运行时间
        long begin = System.currentTimeMillis();

        //2.执行原始的方法
        Object result = pjp.proceed();


        //3.记录方法的结束时间,记录耗时
        long end = System.currentTimeMillis();
        log.info("方法{}执行耗时:{}ms",pjp.getSignature(),end-begin);

        return result;
    }
}
相关推荐
雨中飘荡的记忆2 小时前
MyBatis反射模块详解
java·mybatis
宸津-代码粉碎机2 小时前
Spring 6.0+Boot 3.0实战避坑全指南:5大类高频问题与解决方案(附代码示例)
java·数据仓库·hive·hadoop·python·技术文档编写
笃行客从不躺平2 小时前
ThreadLocal 复习一
java·开发语言
程序帝国2 小时前
SpringBoot整合RediSearch(完整,详细,连接池版本)
java·spring boot·redis·后端·redisearch
安卓程序员_谢伟光2 小时前
如何监听System.exit(0)的调用栈
java·服务器·前端
yangSnowy2 小时前
PHP的运行模式
开发语言·php
Pluto_CSND2 小时前
JSONPath解析JSON数据结构
java·数据结构·json
无限进步_2 小时前
【C语言】用队列实现栈:数据结构转换的巧妙设计
c语言·开发语言·数据结构·c++·链表·visual studio
weixin_579599662 小时前
编写一个程序,输入两个数字的加减乘除余数(Python版)
开发语言·python