springboot获取访问的ip、method、url等数据

1、先掉用"RequestContextHolder"获取"requesAttribute"

ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();

2、再调用"getRequest()"

HttpServletRequest request = requestAttributes.getRequest();

3、获取数据
获取URL: request.getRequestURI()
获取method: request.getMethod();
获取IP: request.getRemoteAddr();
springboot获取访问的ip、method、url等数据_第1张图片

4、请求中的其他数据也可以从request中获取

你可能感兴趣的:(Java,java)