如何在Spring Boot中获取真实的uri地址?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在Spring Boot中获取真实的uri地址?相关的知识,希望对你有一定的参考价值。

@RequestMapping("/test")
public String test() {
    return "test";
}

我编写了一个接口,我想获取该接口的URI,以根据uri进行不同的身份验证。但是我访问localhost / test /也可以路由到/ test我该如何设定我使用getServletPath()方法获得的结果也与/enter image description here

答案

您可以在下面使用:

@RequestMapping(value ="/test")
public String test(HttpServletRequest request){
String test = request.getRequestURI();
return test;
}

以上是关于如何在Spring Boot中获取真实的uri地址?的主要内容,如果未能解决你的问题,请参考以下文章