2015-09-23 18 views
0

我想要生成以下路徑:'/ app#/ fragment1?test = toto' with spring library UriComponentsBuilderUriComponentsBuilder查詢參數和片段

我迄今爲止嘗試:

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

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

任何想法如何以優雅的方式實現這一目標?

回答

1

我只想做這樣的事情:

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

是的,你說得對,這就是我所做的。用查詢參數構建片段作爲UriComponent和完整路徑分開。我會接受你的回答 –