|
@@ -0,0 +1,56 @@
|
|
|
+package com.sysu.admin.support.interceptor;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.sysu.admin.controller.crop.range.AutoTableNameInterceptor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.aspectj.lang.JoinPoint;
|
|
|
+import org.aspectj.lang.annotation.AfterReturning;
|
|
|
+import org.aspectj.lang.annotation.Aspect;
|
|
|
+import org.aspectj.lang.annotation.Before;
|
|
|
+import org.aspectj.lang.annotation.Pointcut;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.web.context.request.RequestAttributes;
|
|
|
+import org.springframework.web.context.request.RequestContextHolder;
|
|
|
+import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
+
|
|
|
+import javax.servlet.ServletRequest;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 用于记录web请求/响应日志
|
|
|
+ */
|
|
|
+@Component
|
|
|
+@Aspect
|
|
|
+@Slf4j
|
|
|
+public class DynamicTableNamesAspect {
|
|
|
+
|
|
|
+ public DynamicTableNamesAspect(){
|
|
|
+ log.info("DynamicTableNamesAspect started! ");
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 切面, 注解名
|
|
|
+ */
|
|
|
+ @Pointcut("@annotation(DynamicTableNames)")
|
|
|
+ private void parameterPointCut() {}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法执行前,记录请求
|
|
|
+ * @param joinPoint
|
|
|
+ */
|
|
|
+ @Before("parameterPointCut()")
|
|
|
+ public void requestLog(JoinPoint joinPoint){
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法执行后,记录响应
|
|
|
+ * @param ret 方法执行结果注入对象
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @AfterReturning(returning = "ret",pointcut = "parameterPointCut()")
|
|
|
+ public Object responeLog(Object ret){
|
|
|
+ AutoTableNameInterceptor.myTable.set(null);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+}
|