Multiple @PathVariable in Spring MVC

user1389920 picture user1389920 · Jul 5, 2012 · Viewed 66.4k times · Source

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

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 ...
    }

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

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?

Thanks!

Answer

aces. picture aces. · Jul 5, 2012
@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?