java - 我可以从 /info/{login} 获得价值吗?
问题描述
我有这门课
@RestController
public class TestController {
@RequestMapping(value = "/info/{login}", method = RequestMethod.GET)
public @ResponseBody String getLogin() {
String login = ?
return login;
}
}
我可以以某种方式解析 {login} 的值吗?
例如:
http://localhost:8080/info/1234
我的方法返回“1234”;
http://localhost:8080/info/298
我的方法返回“298”。
解决方案
您只需要为登录值声明一个变量并使用以下内容进行注释@PathVariable
:
@RestController
public class TestController {
@RequestMapping(value = "/info/{login}", method = RequestMethod.GET)
public @ResponseBody String getLogin(@PathVariable("login") String login) {
return login;
}
}
Baeldung 对强大的选项有很好的解释:https ://www.baeldung.com/spring-requestmapping#path-variable
推荐阅读
- azure - 来自联合表集的 KQL 序列化值
- java - 存储相互依赖的 JsonObjects
- azure - Azure 持久函数、事件中心、事件网格以链接函数
- r - 了解 dplyr 中的 mutate 函数
- node.js - 在 loopback4 中集成 BullMonitorExpress。但队列未反映在 BullMonitorExpress 仪表板中
- informatica - 如何在 informatica power center 10.5 中启用二进制功能
- javascript - 在javascript中为音频元素添加停止/播放按钮
- javascript - 快速排序。为什么 Python 和 Javascript 中的类似实现差异如此显着?
- javascript - 页面有多个视频用于不同的视口。如何使用单个播放按钮播放正确的?
- javascript - 如何使用从第三方 API 的对象数组中获取的值动态映射图标