英文:
How to get the value from the URL
问题
我想动态从URL中获取数值。你能帮助实现吗?
请求URL:
requestForm/intakeReqDetails/3210/request
期望响应:
3210
我可以使用子字符串方法来实现这个,但索引号码应该是硬编码的。你能否提供更好的解决方案?
英文:
I want to get the value from the URL dynamically. Could you please help achieve this?
Request URL:
requestForm/intakeReqDetails/3210/request
Expected Reponse:
3210
I can achieve this using the substring method, but the index number should be hardcoded. Can you please get a better solution?
答案1
得分: 1
我认为使用这种方法你可以获取你想要的:
英文:
I think with this method you can retrieve what you want :
答案2
得分: 0
我将完成@Guillaume的回复,他建议使用一个Spring工具类,但在Java中,我们有Class URL,其中包含一些非常好的方法,只需查看获取方法。
或者@Jorn建议如何使用@PathVariable
@GetMapping(path = "/requestForm/intakeReqDetails/{messageId}/request")
public String getInfo(@PathVariable Integer messageId) {
return "message id: " + messageId;
}
英文:
I will complete @Guillaume response, he suggest to use a spring util class but in java we have Class URL with such a great methods, just have a look at get methods.
Or how @Jorn suggest use @PathVariable
@GetMapping(path = "/requestForm/intakeReqDetails/{messageId}/request")
public String getInfo(@PathVariable Integer messageId) {
return "message id: " + messageId;
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论