Spring RequestMapping: distinguish PathVariable with different types

Is there a way to tell Spring to match the request to another method by the type of the path variable if they are in the same place as uri?
For instance,

@RequestMapping("/path/{foo}") @RequestMapping("/path/{id}") 

If foo is supposedly a string, id is int, is it possible to display the map correctly instead of searching in the request URI?

+4
source share
1 answer

According to spring docs, you can use regex for path variables, here is an example from the docs:

 @RequestMapping("/spring-web/{symbolicName:[az-]+}-{version:\\d\\.\\d\\.\\d}{extension:\\.[az]+}") public void handle(@PathVariable String version, @PathVariable String extension) { // ... } } 

(example taken from http://docs.spring.io/spring/docs/3.2.x/spring-framework-reference/html/mvc.html#mvc-ann-requestmapping-patterns )

Judging by this, it should be possible for your situation to write something like this:

 @RequestMapping("/path/{foo:[az]+}") @RequestMapping("/path/{id:[0-9]+}") 
+8
source

All Articles