' UriComponentsBuilder '在多路径调用中的奇怪行为



如果我查看UriComponentsBuilder的源代码,看起来它正在收集最终将用于创建最终路径的所有路径。

@Override
public UriComponentsBuilder path(String path) {
this.pathBuilder.addPath(path);
resetSchemeSpecificPart();
return this;
}

然而,基于这个假设,我编写了这个失败的测试。似乎UriComponentsBuilder将它们组合成一条简单的路径,而不是用/将它们分开。

@Test
public void testFunctioning(){
String url = UriComponentsBuilder.newInstance()
.path("one")
.path("two")
.path("three")
.toUriString();
assertEquals("one/two/three", url);
}
Expected :one/two/three
Actual   :onetwothree

我对UriComponentsBuilder行为的理解是错误的吗?

我认为你应该使用pathSegment(String... segment),所以像:

UriComponentsBuilder.newInstance()
.pathSegment("one", "two", "three")
.toUriString();

输出/one/two/three

相关内容

  • 没有找到相关文章

最新更新