我想在RestController中获取请求URL。 RestController有多个方法用@RequestMapping
为不同的URI注释,我想知道如何从@RequestMapping
注释中获得绝对URL。如何在Spring Boot RestController中获取请求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;
}
}
感谢您的回复和示例。我知道这种方法,但想知道是否有办法使用控制器级别的任何属性获取url信息,但似乎这是正确的方式。 – NRA
HttpServletRequest从哪里导入? –
javax.servlet.http.HttpServletRequest – Deepak