0

I have a use case. Spring MVC REST Url receive content using the GET method code is as follows:

@RequestMapping("/q/{key}")
public String query(@PathVariable() String key, Model model){
    //todo`
}

But the front end of such a request: /q/SiGeC%2FSi%E5%BC%82%E8%B4%A8%E7%BB%93. %2F decoded character /. The controller can not match mapping request.

How should I do?

Ja͢ck
  • 170,779
  • 38
  • 263
  • 309
howsn
  • 29
  • 1
  • 2
  • Hope this helps. http://stackoverflow.com/questions/4470787/spring-rest-pathvariable-character-encoding – Usha Mar 13 '13 at 19:38

2 Answers2

3

You can include regular expressions in your path variable as such:

@RequestMapping("/q/{key:.*}")

This will grab EVERYTHING after the /q/. Or you can make it a more specific regex to match the pattern you are actually expecting.

CodeChimp
  • 8,016
  • 5
  • 41
  • 79
  • Sorry!This does not work.Threw exception: java.util.regex.PatternSyntaxException: Dangling meta character '*' near index 1 (*)\Q.\E.* – howsn Mar 15 '13 at 07:05
  • Please understand that most people on this site are typing these things from memory. Or at least most of the time I am. I unfortunately don't have a cheat-sheet sitting around with all the answers readily available to paste in and fix everyone's code. I typo'ed the regex (left off the '.'). I updated the posting to reflect the proper regex value. Everything after the ':' is the regex, so make it whatever you want in order to gobble up the proper amount of characters. There are loads of sites that provide online java regex testers, so pick one and go crazy. – CodeChimp Mar 15 '13 at 13:46
2

Annotations of @ PathVariable may not be able to solve this problem.Last use the workaround is resolved.Code is as follows:

@RequestMapping("/q/**")
howsn
  • 29
  • 1
  • 2