一.记录请求信息
@Aspect
@Component
public class HttpAspect {
private static final Logger logger = LoggerFactory.getLogger(HttpAspect.class);
/**
* 这样写是将重复的代码提取出来方便处理
*/
@Pointcut("execution(public * com.kafei.HelloController.*(..))")
public void log() {}
/**
*
* @param joinPoint
* 注意:该方法中的HttpServletRequest为javax.servlet.http.HttpServletRequest;
*/
@Before("log()")
public void doBefore(JoinPoint joinPoint) {
logger.info("1");
ServletRequestAttributes attributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
//记录请求路径url
logger.info("url={}",request.getRequestURL());
//记录请求方式method
logger.info("method={}",request.getMethod());