【问题标题】:spring mvc - The request sent by the client was syntactically incorrectspring mvc - 客户端发送的请求在语法上不正确
【发布时间】:2013-03-21 14:03:17
【问题描述】:

我检查了有关此的线程,但没有一个对我有帮助。我是 spring 新手,当我尝试通过参数发送请求值时出现此错误。

@RequestMapping(value="/receipt", params = "id", method=RequestMethod.GET)
public String index(@PathVariable String id, ModelMap model){
    return "receipt"
}

现在,当我尝试使用以下网址访问网址时:localhost:8080/url/receipt?id=10,我收到了该错误。

【问题讨论】:

    标签: java spring


    【解决方案1】:

    您将 id 声明为 PathVariable,但您将其作为 RequestParamter 传递。

    如果你想通过 url: localhost:8080/url/receipt?id=10 访问你的函数,你应该将你的函数更改为:

    @RequestMapping(value="/receipt",  method=RequestMethod.GET)
    public String index(@RequestParam(value = "id", required = true) String id){
        return "receipt";
    }
    

    【讨论】:

    • 我要补充的一点是@RequestParam的默认必填值为true,所以不需要指定。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-31
    • 2013-12-30
    相关资源
    最近更新 更多