Spring MVC 中的多个@PathVariable [英] Multiple @PathVariable in Spring MVC

查看:69
本文介绍了Spring MVC 中的多个@PathVariable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很遗憾无法找到答案,所以希望有人可以提供帮助.

Couldn't find an answer to this unfortunately so hoping someone can help.

在 Spring MVC 3.1.0 中,这是我的方法:

In Spring MVC 3.1.0 here is my method:

@RequestMapping(value = "/{app}/conf/{fnm}", method=RequestMethod.GET)
public ResponseEntity<?> getConf(@PathVariable String app, @PathVariable String fnm) {
    log.debug("AppName:" + app);
    log.debug("fName:" + fnm);
            ...
            return ...
    }

我在网上看过一些例子,理论上有多个@PathVariables 似乎没有问题.

I've seen some examples online and it appears there is no problem having multiple @PathVariables in theory.

但是,当我这样做时,app"和fnm"都包含相同的值(即分配给app"的任何值).

However when I do it, both "app" and "fnm" contain the same value (which is whatever value was assigned to "app").

真的很感激有人对我哪里出错的任何见解吗?

Really appreciate any insight someone may have to where I'm going wrong?

谢谢!

推荐答案

@RequestMapping(value = "/{app}/conf/{fnm}", method=RequestMethod.GET)
public ResponseEntity<?> getConf(@PathVariable("app") String app, @PathVariable("fnm") String fnm) {
   log.debug("AppName:" + app);
   log.debug("fName:" + fnm);
           ...
           return ...
  }

基本上路径变量需要在方法参数中用括号指定.这有帮助吗?

Basically path variables need to be specified with parentheses, in method arguments. Does this help?

这篇关于Spring MVC 中的多个@PathVariable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆