网上杂七杂八的资料也太多了
搞懂之后直接一个demo记录一下
首先
创建自定义注解
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface CallLog {
//自定义参数名: state
// default 定义默认值
String value() default "";
}
定义切面
@Aspect
@Component
public class CallLogAspect {
@Resource
private CallLogMapper callLogMapper;
@Pointcut("@annotation(aopTarget)")
public void annotationPointcut(CallLog aopTarget) { }
@AfterReturning(pointcut = "annotationPointcut(aopTarget)", returning = "result")
public void doAfterReturning(JoinPoint joinPoint, CallLog aopTarget, Object result) throws Throwable {
//获得url
HttpServletRequest request = ((ServletRequestAttributes)
RequestContextHolder.getRequestAttributes()).getRequest();
String requestURI = request.getRequestURI();
CallLog callLog