UriComponentsBuilder查询param和fragment

问题描述 投票:2回答:1

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

知道如何以优雅的方式实现这一目标吗?

spring relative-path url-encoding query-parameters
1个回答
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"
© www.soinside.com 2019 - 2024. All rights reserved.