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!
4. Multiple Path Variables in a Single Request. There is, however, a small catch while handling multiple @PathVariable parameters when the path variable string contains a dot(.) character.
Try this: @RequestMapping(value = "/{lang}/{count}/{term}", method=RequestMethod. GET) public ResponseEntity<?> getSomething(@PathVariable("lang") String lang, @PathVariable("count") String count, @PathVariable("term") String term) { // Your code goes here. }
@PathVariable is a Spring annotation which indicates that a method parameter should be bound to a URI template variable. If the method parameter is Map<String, String> then the map is populated with all path variable names and values. It has the following optional elements: name - name of the path variable to bind to.
@RequestParam and @PathVariable can both be used to extract values from the request URI, but they are a bit different.
@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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With