0

I would like to use Spring MVC @RequestMapping annotation to attach my controller to requests in such way:

@RequestMapping(method = RequestMethod.GET, value="/prod/{value:.+}/show")
 public String getProduct(
        @PathVariable("value") String value, 
        ModelMap modelMap, HttpServletRequest request, HttpServletResponse response) { 
        ...
 }

and when request will be

(..)/prod/foo/show

my value variable will have foo

and when request will be

(..)/prod/foo/bar/show

my value variable will have foo/bar etc

Is there any way to do that? What @RequestMapping wildcards are supported?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Random
  • 4,519
  • 2
  • 38
  • 46

2 Answers2

0

You can use regular expressions. All though you might have to do some escaping. Check out this jira ticket.

skaffman
  • 398,947
  • 96
  • 818
  • 769
Karthik Ramachandran
  • 11,925
  • 10
  • 45
  • 53
  • What is the default pattern used to parse @RequestMapping params? I've already put dots (like above) to be included. Is that pattern built in somehow incremental way or absolute and i must define all regex from the scratch? – Random May 05 '11 at 02:16
  • could you clarify what you mean by incremental vs. absolute? – Karthik Ramachandran May 05 '11 at 02:54
  • i mean if i put some regex there will it overwrite default pattern or be combined with it – Random May 05 '11 at 05:22
0

If I understood you well that you need to pass from your view to the controller a String, for example, that contains some wild character. When you receive this String on the controller you will just find the values before your wild character.

This behavior makes sense as you can't add "." or "/" ,"#" into url . If you are using a freemarker , you can do this by using ?url :http://freemarker.sourceforge.net/docs/ref_builtins_string.html#ref_builtin_url

Additionally, the ".",the dot as you can see here : http://www.december.com/html/spec/esccodes.html doesn't have ASCII hexadecimal equivalent code so you will need to alter it from the code to be something like "#" to be passed from the view to the controller.

Marcin Gil
  • 68,043
  • 8
  • 59
  • 60
Echo
  • 2,959
  • 15
  • 52
  • 65
  • Regarding the nasty workaround I told you about,using #,forget it and use that :http://forum.springsource.org/showthread.php?78085-Problems-with-RequestMapping&p=263563#post263563 – Echo Apr 20 '12 at 11:55