【问题标题】:Spring MVC referencing params variable from RequestMappingSpring MVC 从 RequestMapping 引用 params 变量
【发布时间】:2011-06-27 10:01:15
【问题描述】:

我有以下方法:

@RequestMapping(value = "/path/to/{iconId}", params="size={iconSize}", method = RequestMethod.GET)
public void webletIconData(@PathVariable String iconId, @PathVariable String iconSize, HttpServletResponse response) throws IOException {
    // Implementation here
}

我知道如何使用 @PathVariable 从 RequestMapping 传递变量“webletId”,但是如何从参数中引用变量“iconSize”?

非常感谢。

【问题讨论】:

    标签: java spring spring-mvc servlets request-mapping


    【解决方案1】:

    使用@RequestParam:

    @RequestMapping(value = "/path/to/{iconId}", method = RequestMethod.GET) 
    public void webletIconData(@PathVariable String iconId, 
        @RequestParam("size") String iconSize, 
        HttpServletResponse response) throws IOException { ... }
    

    另请参阅:

    【讨论】:

      【解决方案2】:

      axtavt是对的

      我只想解释你的错误是什么:

      @RequestMappingparams 参数是一个过滤器,用于确保仅在存在具有请求值的参数时才调用带注释的处理程序方法。

      因此,只有当请求参数action具有内容doSomething时,才会调用带有@RequestMapping(params="action=doSomething")注释的处理程序方法。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-12-12
        • 2018-11-02
        • 2015-06-22
        • 2011-07-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-03-29
        相关资源
        最近更新 更多