2017-06-14 80 views
0

我發現了幾種設置上下文路徑的方法,但是在spring引導應用程序中沒有找到獲取上下文路徑的方法。有一種方法可以通過@Value(「server.contextPath」)獲得它,但我正在尋找更優雅的方式來獲取它。在spring引導應用程序中獲取聯繫路徑

回答

0

如果您願意,您可以傳入請求並使用request.getContextPath

查看Javadoc看看這是否適合你?

0

您可以在application.properties文件中設置contextPath。

是這樣的:

server.contextPath=/yourChosenContextPath 
1

可以在控制器獲取上下文路徑爲:

@RequestMapping(method = RequestMethod.GET, value = "/getUsers") 
public String getUsers(HttpServletRequest request) { 
    String path = request.getContextPath(); 
    //... 
} 
相關問題