【问题标题】:UriComponentsBuilder query param and fragmentUriComponentsBuilder 查询参数和片段
【发布时间】:2018-09-19 05:36:40
【问题描述】:

我想生成以下路径:'/app#/fragment1?test=toto' 带有 spring 库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】:

    我只会做类似的事情:

    // 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 和完整路径。我会接受你的回答
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-24
    • 2015-07-03
    • 1970-01-01
    • 1970-01-01
    • 2014-04-01
    • 1970-01-01
    相关资源
    最近更新 更多