我想通过Spring的UriComponentsBuilder作为路径的前缀。但是,它的path()方法看起来只能附加路径。
例如,我希望下面的代码能够工作:
UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString("/foo?name=john");
// prepend "/bar" in the path in some way
String uri = uriComponentsBuilder.build().toUriString(); // so that "uri" can be "/bar/foo?name=john"谢谢。
发布于 2021-10-14 23:25:50
如果使用buildAndExpand将path token替换为您的预端路径:
String uri = UriComponentsBuilder
.fromUriString("{prePath}/foo?name=john")
.buildAndExpand("bar")
.toString();
System.out.println(uri);这应该会给你提供:
bar/foo?name=johnhttps://stackoverflow.com/questions/69575007
复制相似问题