UriComponentsBuilder 查询参数和片段

UriComponentsBuilder query param and fragment

我想生成以下路径:'/app#/fragment1?test=toto' with spring library UriComponentsBuilder.

到目前为止我尝试过的:

UriComponentsBuilder ucb = UriComponentsBuilder.fromPath("/app").fragment("fragment1").queryParam("test","toto");

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

知道如何优雅地实现这一点吗?

我只会做类似的事情:

// 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"