Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring MVC referencing params variable from RequestMapping

I have the method below:

@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
}

I know how to pass the variable "webletId" from the RequestMapping using the @PathVariable, but how do I reference the variable "iconSize" from params?

Thanks a lot.

like image 987
NomNomNom Avatar asked Feb 15 '11 07:02

NomNomNom


2 Answers

Use @RequestParam:

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

See also:

  • 15.3.2.3 Supported handler method arguments and return types
like image 89
axtavt Avatar answered Oct 14 '22 09:10

axtavt


axtavt is right

I only want to explain what your mistake is:

The @RequestMapping params parameter is a filter to make sure that the annotated handler method is only invoked if there is a parameter with the requested value.

So a handler method annotated with @RequestMapping(params="action=doSomething") will be only invoked if there is an request parameter actionwith the content doSomething.

like image 25
Ralph Avatar answered Oct 14 '22 10:10

Ralph