Spring RESTful URL 调用传递参数 [英] Spring RESTful URL call passing parameters
问题描述
如果 testId 为 1211.ml:FA890987422,我如何对以下方法进行 URL 调用.由于 testId 中有一个:",我尝试使用 URLEncoding (%3A for :) 发出请求
How do I make a URL call to the following method if the testId is 1211.ml:FA890987422. Since there is a ':' in the testId, I try to make a request using URLEncoding (%3A for :) like this
http://localhost:8080/test/1211.ml%3AFA890987422
当我使用上面的 URL 时,我得到的 testId 为 1211 而不是 1211.ml:FA890987422,即使是 '.'不需要 URL 编码.我究竟做错了什么?另外,如果我想跳过 URL 编码,还有其他方法可以将这个 testId 传递给这个方法吗?
When I use the above URL, I get testId as 1211 as opposed to 1211.ml:FA890987422 even though '.' does not require URL encoding. What am I doing wrong? Also, would there be any other way to pass this testId to this method if I want to skip URL encoding?
@RequestMapping(value = "/test/{testId}",
method = RequestMethod.GET,
produces = "application/xml")
public @ResponseBody String testResource(
@PathVariable String testId){
System.out.println("Test Id: "+ testId)
// other codes follow
}
推荐答案
重复问题 Spring MVC @PathVariable 被截断.
尝试在请求映射中使用正则表达式,它应该可以让您获取整个字符串.
Try using regular expression in the request map and it should let you grab the entire string.
这篇关于Spring RESTful URL 调用传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!