spring - Spring boot:使用 ServletUriComponentsBuilder 构建一个 uri“/{id}”
问题描述
目前,我正在使用此代码片段来创建 uri 引用:
URI uri = ServletUriComponentsBuilder
.fromCurrentContextPath()
.path(EspaiDocConstants.Endpoints.DOWNLOAD)
.path(attributes.getId())
.build()
.toUri();
但是,它会生成:
http://localhost:8080/downlo**adcp**d4-6b9f27c1-e9b3-4735-8127-8f18724734e9
中间**adcp**
没有斜线!
我该如何解决?
解决方案
看起来path()
只是连接字符串。您可以自己添加斜线
.path(EspaiDocConstants.Endpoints.DOWNLOAD)
.path("/")
.path(attributes.getId())
推荐阅读
- python - 无法获取部署在 Flask 上的 Python 脚本的输入
- java - JUnit 5 @ParamterizedTest {arguments} 与 {argumentsWithNames} 占位符
- android - Slack 像底页对话框片段
- python - ValueError: 层序贯_10 的输入 0 与层不兼容:预期 ndim=5,发现 ndim=4。Alexnet(cnn) + LSTM
- java - 是否可以使用 Java 下载整个 YouTube 播放列表,更具体地说是 Android Studio
- java - 如何在 Java 中禁用 linting?
- ruby-on-rails - Rspec ArgumentError:参数数量错误(给定 2,预期为 0)
- laravel - 如何在 Laravel 中获取分页查询的总和
- arrays - 算法:是否可以扫描(迭代行、列、对角线和反向对角线)一个简单的数组?
- c# - 如何使用互操作或打开 xml sdk c#为幻灯片添加过渡到 powerpoint