//加入bean @Component //指定这是一个aop类 @Aspect @Slf4j public class AOPlogin { @Autowired logrizhi diaoyong; //获取传递过来jwt令牌 @Autowired HttpServletRequest jwtlog ; //@annotation(* com.example.tlias.AOPbao.loginin // @Pointcut("@annotation(* com.example.tlias.sevicechuli.mylog") @Order(1) @Around("@annotation(com.example.tlias.AOPbao.loginin)")//切入点表达式 //加入ProceedingJoinPoint joinPoint 表示那个类需要被AOP动态代理 public Object aopp(ProceedingJoinPoint joinPoint) throws Throwable { //1.获取前端传递过来的jwt令牌"token"参照接口文档 String token = jwtlog.getHeader("token"); //2.解析jwt令牌 Claims pase = jwttuil.pase(token); //3.获取jwt令牌里面传递的id属性 Integer id = (Integer) pase.get("id"); //获取当前操作时间 LocalDateTime now = LocalDateTime.now(); //获取目标类名fdaanhuan String name = joinPoint.getTarget().getClass().getName(); log.info("获取目标类名"+name); //获取操作方法名 com.example.tlias.conller.conllemp String name1 = joinPoint.getSignature().getName(); log.info("操作方法名"+name1); //获取目标方法形参数 Object[] args = joinPoint.getArgs(); String s = Arrays.toString(args); long l = System.currentTimeMillis(); //调用目标方法 Object proceed = joinPoint.proceed(); //把返回值变成json格式字符串 String s1 = JSONObject.toJSONString(proceed); long I2 = System.currentTimeMillis(); long tmemsj = I2-l; OperateLog operateLog = new OperateLog(null,id,now,name,name1,s,s1,tmemsj ); diaoyong.insertadd(operateLog); return proceed; } }
AOP使用案例
于 2024-02-01 16:25:32 首次发布