我想生成以下路径:'/ 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"