Spring MVC referencing params variable from RequestMapping

后端 未结 2 1010
情话喂你
情话喂你 2020-12-28 15:29

I have the method below:

@RequestMapping(value = \"/path/to/{iconId}\", params=\"size={iconSize}\", method = RequestMethod.GET)
public void webletIconData(@P         


        
相关标签:
2条回答
  • 2020-12-28 15:54

    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
    0 讨论(0)
  • 2020-12-28 16:05

    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.

    0 讨论(0)
提交回复
热议问题