作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
目前我们正处于产品的开发阶段,坦率地说,已经编写了许多 Controller /服务。我们使用 Spring MVC、Core、Aspect、Security 等以及 Hibernate、JQuery 等。
现在我们需要捕获登录的用户 Activity ,例如按钮点击、菜单点击、超链接点击等。
一种方法是我使用Spring Aspect
,并创建我自己的注释
或在spring中使用内置的(如果有的话)。但问题是,我必须手动将其添加到我的应用程序中的所有 Controller 中。请参阅 this .
处理请求时,调度程序 servlet 周围的某个地方在全局级别
上是否有可用的东西。 (就像@ControllerAdvice和@ExceptionHandler
)
最佳答案
Spring AOP或AspectJ中的切入点不仅可以基于手动添加的注释,还可以基于您想要拦截的方法的其他常见特征,例如
及其任意组合。你可能可以走得很远。但为了给出更具体的答案,我必须更多地了解您的代码。
<小时/>更新:既然你告诉了我共同点,我有一个想法给你:
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/
我是一名优秀的程序员,十分优秀!