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;
    }
}
相关推荐
今天AI了吗25 分钟前
Python 基础语法(一):常量、变量、输入输出与运算符
开发语言·数据库·人工智能·python·sql·深度学习·机器学习
TELL5211 小时前
selenium webdriver 第二次初始化的异常
开发语言·python
动词ing1 小时前
【C语言】自定义函数+指针入门
c语言·开发语言·算法
重生之后端学习2 小时前
283. 移动零[简单]✅
开发语言·数据结构·算法·leetcode·职场和发展
吠品2 小时前
Wine 在 Linux 上运行 Windows 软件完整指南
java·linux·服务器
动词ing3 小时前
【C语言】结构体+文件基础
c语言·开发语言·数据结构
caimouse3 小时前
ReactOS 窗口系统分析(7):分层窗口与绘制辅助 — layered.c + draw.c
c语言·开发语言
亚历克斯神3 小时前
智能搜索系统的升级复盘——从 Elasticsearch 到混合检索的检索质量提升
java·spring·微服务
丰锋ff3 小时前
基于 Qt 的智慧社区物业管理系统
开发语言·qt
夜不会漫长4 小时前
C++入门(1)
开发语言·c++·算法