Java – regular expression in spring controller
•
Java
I'm trying to build a request filter that will only be used if it matches the pattern of the letter E and then a number But I can't seem to make it work Every time I try to use regular expressions, I get 400 errors
If I just use it below to "work", but also capture the mapping without numbers I don't want
@RequestMapping(value = "e{number}",method = RequestMethod.GET)
I have tried the following combinations
@RequestMapping(value = "e{number}",params = "number:\\d+",method = RequestMethod.GET) @RequestMapping(value = "e{number:\d+}",method = RequestMethod.GET) @RequestMapping(value = "/e{^\\+?\\d+\$}",method = RequestMethod.GET) @RequestMapping(value = "/{^\\e+?\\d+\$}",method = RequestMethod.GET)
Solution
According to the document, you must use something like {Varname: regex} There is even an example:
@RequestMapping("/spring-web/{symbolicName:[a-z-]+}-{version:\\d\\.\\d\\.\\d}{extension:\\.[a-z]+}") public void handle(@PathVariable String version,@PathVariable String extension) { // ... } }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码