代码之家  ›  专栏  ›  技术社区  ›  LG_

UriComponentsBuilder查询参数和片段

  •  5
  • LG_  · 技术社区  · 9 年前

    我想生成以下路径: '/app#/fragment1?测试=总计 带弹簧库 UriComponentsBuilder .

    到目前为止,我已经尝试过:

    UriComponentsBuilder ucb = UriComponentsBuilder.fromPath("/app").fragment("fragment1").queryParam("test","toto");
    
    ucb.toUriString(); // -> gives me as result : '/app?test=toto#/fragment1'
    

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

    1 回复  |  直到 6 年前
        1
  •  4
  •   LG_    9 年前

    我会简单地做一些事情,比如:

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