gpt4 book ai didi

java - 捕获登录用户页面访问/点击图像/超链接/按钮 - 用户 Activity 审核跟踪

转载 作者:行者123 更新时间:2023-11-30 03:39:56 25 4
gpt4 key购买 nike

目前我们正处于产品的开发阶段,坦率地说,已经编写了许多 Controller /服务。我们使用 Spring MVC、Core、Aspect、Security 等以及 Hibernate、JQuery 等。

现在我们需要捕获登录的用户 Activity ,例如按钮点击、菜单点击、超链接点击等。

一种方法是我使用Spring Aspect,并创建我自己的注释或在spring中使用内置的(如果有的话)。但问题是,我必须手动将其添加到我的应用程序中的所有 Controller 中。请参阅 this .

处理请求时,调度程序 servlet 周围的某个地方在全局级别上是否有可用的东西。 (就像@ControllerAdvice和@ExceptionHandler)

最佳答案

Spring AOP或AspectJ中的切入点不仅可以基于手动添加的注释,还可以基于您想要拦截的方法的其他常见特征,例如

  • 包名称模式,
  • 类名称模式,
  • 方法名称模式,
  • 方法签名(某些参数类型),
  • 类层次结构(例如,特定类或接口(interface)的所有子类)

及其任意组合。你可能可以走得很远。但为了给出更具体的答案,我必须更多地了解您的代码。

<小时/>

更新:既然你告诉了我共同点,我有一个想法给你:

package de.scrum_master.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.web.bind.annotation.RequestMapping;

public aspect RequestMappingInterceptor {
@Pointcut(
"within(@org.springframework.stereotype.Controller *) && " +
"@annotation(requestMapping) && " +
"execution(* *(..))"
)
public void controller(RequestMapping requestMapping) {}

@Before("controller(requestMapping)")
public void advice(RequestMapping requestMapping, JoinPoint thisJoinPoint) {
System.out.println(thisJoinPoint);
System.out.println(" " + requestMapping);
System.out.println(" " + requestMapping.method()[0]);
}
}

此示例拦截所有 Controller 中的所有公共(public)方法,并将请求映射注释绑定(bind)到您可以轻松评估的参数。

关于java - 捕获登录用户页面访问/点击图像/超链接/按钮 - 用户 Activity 审核跟踪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27010184/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com