如何使用UricomponentsBuilder替换程体
我有一个URL,如下所示,
http://example.com/{id}
我想将其更改为
http://example.com/12
我的编码,
url= "http://example.com/{id}";
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(url);
builder.pathSegment("{id}", "12");
UriComponents uriComponents = builder.build().encode();
URI uri = uriComponents.toUri();
System.out.println(uri);
因为它在其下方已将输出
http://example.com/%7Bid%7D/id/12
不确定是什么是使用UricomponentsBuilder的正确方法
I have a url as below
http://example.com/{id}
I want to change it to
http://example.com/12
I have coded as below
url= "http://example.com/{id}";
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(url);
builder.pathSegment("{id}", "12");
UriComponents uriComponents = builder.build().encode();
URI uri = uriComponents.toUri();
System.out.println(uri);
Its giving me output as
http://example.com/%7Bid%7D/id/12
Not sure what is right way to use UriComponentsBuilder
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要用一个实际值替换占位符,您需要用参数调用
构建
To replace placeholder with a real value, you need to call
build
with parameters