【问题标题】:Spring RESTful URL call passing parametersSpring RESTful URL 调用传递参数
【发布时间】:2014-04-24 17:13:46
【问题描述】:

如果 testId 为 1211.ml:FA890987422,我如何对以下方法进行 URL 调用。由于 testId 中有一个 ':',我尝试使用 URLEncoding (%3A for :) 发出请求,如下所示

http://localhost:8080/test/1211.ml%3AFA890987422

当我使用上面的 URL 时,我得到 testId 作为 1211 而不是 1211.ml:FA890987422 即使是 '.'不需要 URL 编码。我究竟做错了什么?另外,如果我想跳过 URL 编码,还有其他方法可以将这个 testId 传递给这个方法吗?

@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 rest uri


    【解决方案1】:

    重复的问题 Spring MVC @PathVariable getting truncated

    尝试在请求映射中使用正则表达式,它应该可以让您抓取整个字符串。

    【讨论】:

    • 谢谢,我搜索了但找不到完全匹配,可能是我的搜索字符串不合适
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-20
    • 2013-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-03
    相关资源
    最近更新 更多