Spring MVC引用RequestMapping中的params变量

Nom*_*Nom 23 java spring servlets spring-mvc request-mapping

我有以下方法:

@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
}
Run Code Online (Sandbox Code Playgroud)

我知道如何使用@PathVariable从RequestMapping传递变量"webletId",但是如何从params引用变量"iconSize"?

非常感谢.

axt*_*avt 41

用途@RequestParam:

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

也可以看看:


Ral*_*lph 18

axtavt是对的

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

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

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