Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring-MVC PathVariable matching regular expression not starting with word

I want to match all requests with a PathVariable which are not start with 'api'. I test following RequestMapping. spring could match request but could not get value for PathVariable. How I solve this?

@RequestMapping(value = "/{name:(?!api).+}", method = RequestMethod.GET)
public void getNotApi(@PathVariable String name, HttpServletResponse response) {
    ...
}

I get following message for some request like localhost:8080/resource.

Error 500 Missing URI template variable 'name' for method parameter of type String

like image 760
hadi.mansouri Avatar asked Jun 22 '17 19:06

hadi.mansouri


1 Answers

@RequestMapping(value = "/{name:^(?!api).+}", method = RequestMethod.GET)
like image 114
fg78nc Avatar answered Sep 29 '22 12:09

fg78nc