当前位置: 首页 > news >正文

Spring Boot通过切面实现方法耗时情况

Spring Boot通过切面实现方法耗时情况

依赖

        <dependency><groupId>org.aspectj</groupId><artifactId>aspectjweaver</artifactId><version>1.9.9.1</version></dependency>

自定义注解

package com.geekmice.springbootselfexercise.annotation;import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;/*** @author PMB*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface MethodExporter {
}

切面类

package com.geekmice.springbootselfexercise.aspect;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;/*** @BelongsProject: spring-boot-scaffold* @BelongsPackage: com.geekmice.com.geekmice.sbpagehelper.utils* @Author: pingmingbo* @CreateTime: 2023-07-26  21:52* @Description: TODO* @Version: 1.0*/
@Aspect
@Component
@Slf4j
public class MethodExporterAspect {@Around("@annotation(com.geekmice.springbootselfexercise.annotation.MethodExporter)")public Object methodExporter(ProceedingJoinPoint point) throws Throwable {long start = System.currentTimeMillis() / 1000;Object proceed = point.proceed();long end = System.currentTimeMillis() / 1000;log.info("【耗时:】{}s", (end - start));return proceed;}
}

控制层

    /*** 服务对象*/@Resourceprivate UserService userService;@PostMapping(value = "uploadFileByEasyPoi")@MethodExporter@ApiOperation(value = "通过easypoi上传文件")public AjaxResult uploadFileByEasyPoi(@RequestPart MultipartFile file){userService.uploadFileByEasyPoi(file);return AjaxResult.success();}

在这里插入图片描述

http://www.lryc.cn/news/111402.html

相关文章:

  • 深挖 Threads App 帖子布局,我进一步加深了对CSS网格布局的理解
  • leetcode做题笔记54
  • GD32F103VE点灯
  • matlab使用教程(8)—绘制三维曲面图
  • 【Nginx14】Nginx学习:HTTP核心模块(十一)其它配置
  • 243. 一个简单的整数问题2(树状数组)
  • C#利用自定义特性以及反射,来提大型项目的开发的效率
  • 【传统视觉】C#创建、封装、调用类库
  • AutoMapper反向映射
  • 华为Mate30报名鸿蒙 HarmonyOS 4.0.0.108 系统更新
  • elementui Cascader 级联选择使用心得
  • 【ChatGPT 指令大全】怎么利用ChatGPT写报告
  • 【枚举,构造】CF1582 C D
  • POJ 3169 Layout BellmanFord Dijkstra
  • 数据库管理员知识图谱
  • 中兴服务器支持百度“文心一言”,助力AI产业发展
  • STM 如何通过网络 time.windows.com获取时间
  • 数据结构——红黑树
  • 【C++】数据结构与算法:常用排序算法
  • 【C++】Bullet3代码存档
  • 弘扬“两弹一星”精神,勇攀科学技术高峰——道本科技商业大学党日活动圆满落幕
  • Java中创建对象的几种方式
  • Python(三)
  • android 如何分析应用的内存(十五)——Visual Studio Code 调试Android应用
  • 宁波银行最新内推码 MK4913
  • postgresql|数据库|MySQL数据库向postgresql数据库迁移的工具pgloader的部署和初步使用
  • 【Python从小白到高手】---函数基础
  • postman----传参格式(json格式、表单格式)
  • Uni-Dock:GPU 分子对接使用教程
  • 【Python】数据分析+数据挖掘——掌握Python和Pandas中的单元格替换操作