Spring RESTful URL call passing parameters

允我心安 提交于 2020-01-16 18:25:18

问题


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

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

}


回答1:


Duplicate question Spring MVC @PathVariable getting truncated .

Try using regular expression in the request map and it should let you grab the entire string.



来源:https://stackoverflow.com/questions/23275524/spring-restful-url-call-passing-parameters

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!