Spring MVC referencing params variable from Reques

2019-02-02 05:15发布

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.

2条回答
男人必须洒脱
2楼-- · 2019-02-02 05:20

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:

查看更多
一夜七次
3楼-- · 2019-02-02 05:33

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.

查看更多
登录 后发表回答