我找到了几种设置上下文路径的方法,但无论如何都没有找到在 Spring Boot 应用程序中获取上下文路径。有一种方法可以通过 @Value("server.contextPath") 获取它,但我正在寻找更优雅的方式来获取它。
最佳答案
您可以在 Controller 中获取上下文路径:
@RequestMapping(method = RequestMethod.GET, value = "/getUsers")
public String getUsers(HttpServletRequest request) {
String path = request.getContextPath();
//...
}
关于java - 在 Spring Boot 应用程序中获取联系路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44548149/