Spring MVC 从 RequestMapping 引用 params 变量
我有以下方法:
@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”?
多谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用@RequestParam:
另请参阅:
Use
@RequestParam
:See also:
axtavt是对的
我只想解释一下你的错误是:
@RequestMapping
params
参数是一个过滤器,用于确保仅在存在具有请求值的参数时才调用带注释的处理程序方法。因此,仅当存在内容为
doSomething< 的请求参数
action
时,才会调用使用@RequestMapping(params="action=doSomething")
注释的处理程序方法/代码>。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 parameteraction
with the contentdoSomething
.