Spring MVC中的多个@PathVariable


问题内容

不幸的是,找不到答案,因此希望有人可以提供帮助。

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

@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似乎没有问题。

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

真的很感谢别人对我要去哪里的任何见解?

谢谢!


问题答案:
@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 ...
  }

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