gpt4 book ai didi

java - 字符串启动 : UriComponentsBuilder toString

转载 作者:行者123 更新时间:2023-11-30 01:57:35 28 4
gpt4 key购买 nike

我遇到了一个问题,我想它必须很容易解决,但我坚持了下来。

这是我的代码片段:

String url = UriComponentsBuilder.fromPath("http://localhost")
.build().toUriString();

url 的值为:

http:/localhost

如您所见,:// 被替换为 :/

关于如何解决这个问题有什么想法吗?

最佳答案

fromPath 将仅采用 API 或资源路径,例如 /api/student。但它并不像您的情况那样需要整个网址。一种替代方案是,

UriComponentsBuilder.fromUriString("http://localhost")
.build().toUriString();

或者也可以使用以下方法完成相同的操作:

UriComponentsBuilder.newInstance().scheme("http").host("localhost").build().toString();

关于java - 字符串启动 : UriComponentsBuilder toString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53853842/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com