30

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!

user1389920
  • 403
  • 1
  • 6
  • 12

1 Answers1

47
@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?

aces.
  • 3,902
  • 10
  • 38
  • 48
  • Sorry, I should have specified that. I have tested without the variable name, with the variable name and also explicitly trying (value="_some_pathvarname"). All of which produce the same results :( – user1389920 Jul 05 '12 at 19:19
  • @user1389920 : Have you tried hardcoding request url with different values; For Example: /XYZ/conf/ABC and then check what gets mapped to the Controller? this is to verify that request is correctly formed... – aces. Jul 05 '12 at 19:22
  • Thanks, found the problem. fnm was being truncated so the test values looked the same... sorry bit of brain fade on this one. I have the correct regex now and it's working, thank you all for help! – user1389920 Jul 05 '12 at 19:25