How to extract IP Address in Spring MVC Controller get call?

后端 未结 9 563
长发绾君心
长发绾君心 2020-11-28 04:04

I am working on Spring MVC controller project in which I am making a GET URL call from the browser -

Below is the url by which I am making a GET call from the browse

9条回答
  •  南笙
    南笙 (楼主)
    2020-11-28 04:43

    You can get the IP address statically from the RequestContextHolder as below :

    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes())
            .getRequest();
    
    String ip = request.getRemoteAddr();
    

提交回复
热议问题