【问题标题】:How does localhost get fed into {host} and "1234" gets fed into {id}localhost 如何输入 {host} 和 "1234" 如何输入 {id}
【发布时间】:2014-09-11 21:53:23
【问题描述】:

有人可以向我解释一下“localhost”将如何输入到 {host} 中,“1234”将如何输入到 {id} 中吗?

引用:

Link.Builder 有一个底层的 UriBuilder。传递给 build() 的值 方法被传递给此 UriBuilder 以创建链接的 URI。我们看看吧 举个例子:

   Link link = Link.fromUri("http://{host}/root/customers/{id}")
                   .rel("update").type("text/plain")
                   .build("localhost", "1234");  

在链接实例上调用 toString() 将导致:

<http://localhost/root/customers/1234>; rel="update"; type="text/plain"

结束报价

谢谢

【问题讨论】:

    标签: resteasy


    【解决方案1】:

    UriBuilder 还引入了一组方法,这些方法通过将单个模板替换为提供的值来提供解析 URI 模板的方法。

    final URI uri = UriBuilder.fromUri("http://{host}/{path}?q={param}")
        .resolveTemplate("host", "localhost")
        .resolveTemplate("path", "myApp")
        .resolveTemplate("param", "value").build();
    
    uri.toString(); // returns "http://localhost/myApp?q=value"
    

    【讨论】:

    • 但作者从未使用过任何类型的分辨率,所以我不知道主机如何获取本地主机等。我的意思是,据我所知,主机可能是 1234,id 可能是本地主机.
    猜你喜欢
    • 2010-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-24
    • 2016-05-09
    • 1970-01-01
    • 2017-11-18
    • 1970-01-01
    相关资源
    最近更新 更多