本地请求spring项目的时候,获取请求的ip地址,假如你的写法是:

((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getRemoteAddr()

1.如果的请求是用的 localhost

http://localhost:8080/xxxx

对应的值就是: 0:0:0:0:0:0:0:1

 2.如果的请求是用的 127.0.0.1

http://localhost:8080/xxxx127.0.0.1http://localhost:8080/xxxx

对应的值就是: 127.0.0.1

 3.如果的请求是用的 本机实际ip

http://xxxxxxx:8080/xxxx

对应的值就是: x.x.x.x

更多推荐