UriComponentsBuilder查询参数和片段

5
我希望使用Spring库UriComponentsBuilder生成以下路径:'/app#/fragment1?test=toto'
到目前为止,我尝试过:
UriComponentsBuilder ucb = UriComponentsBuilder.fromPath("/app").fragment("fragment1").queryParam("test","toto");

ucb.toUriString(); // -> gives me as result : '/app?test=toto#/fragment1'

有什么优雅的方法可以实现这个吗?
1个回答

6
我会简单地执行以下操作:

我会简单地执行以下操作:

// first build fragment part
String fragmentWithQueryParams = UriComponentsBuilder.fromPath("/fragment1").queryParam("test","toto").toUriString();

// then generate full path
String fullPath = UriComponentsBuilder.fromPath("/app").fragment(fragmentWithQueryParams).toUriString());

System.out.println(fullPath); // -> "/app#/fragment1?test=toto"

是的,你说得对,那就是我所做的。使用 UriComponent 和完整路径分别构建带有查询参数的片段。我会接受你的答案。 - LG_

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接