如何在 Controller 中使用查询参数但没有基本 URL 来获取当前映射?例如/foo/bar?boom=bam
?
我尝试使用 UriComponentsBuilder 作为 Controller 中的参数,但这会导致 http://localhost
,
我尝试使用 ServletUriComponentsBuilder.fromCurrentContextPath(),但这会导致 http://localhost?boom=bam
。
我只想使用查询参数进行当前映射,而无需解析内容
最佳答案
您可以将 HttpServletRequest 指定为 Controller 方法参数并查询:
https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#mvc-ann-methods
https://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html
public void controllerMethod(HttpServletRequest request){
String path = request.getServletPath();
String queryString = request.getQueryString();
}
关于Java Spring : get current mapping in the controller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56836851/