23

我有以下方法:

@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”?

非常感谢。

4

2 回答 2

41

使用@RequestParam

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

也可以看看:

于 2011-02-15T08:29:45.307 回答
18

axtavt是对的

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

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

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

于 2011-02-15T10:59:09.053 回答