我正在尝试在 RestController 中获取请求 URL。 RestController 有多个用 @RequestMapping
注释的方法,用于不同的 URI,我想知道如何从 @RequestMapping
注释中获取绝对 URL。
@RestController
@RequestMapping(value = "/my/absolute/url/{urlid}/tests"
public class Test {
@ResponseBody
@RequestMapping(value "/",produces = "application/json")
public String getURLValue(){
//get URL value here which should be in this case, for instance if urlid
//is 1 in request then "/my/absolute/url/1/tests"
String test = getURL ?
return test;
}
}
原文由 NRA 发布,翻译遵循 CC BY-SA 4.0 许可协议
您可以尝试将类型为
HttpServletRequest
的附加参数添加到getUrlValue()
方法: