My controller mappings:
@RequestMapping(value = "{objectId}/{objectName: [a-zA-Z-]+}", method = GET)
public String getObjects(@PathVariable Integer objectId, Model model) { ... }
@RequestMapping(value = "{objectId}/{objectName: [a-zA-Z-]+}_{category}", method = GET)
public String getObjectsForCategories(@PathVariable Integer objectId,
@PathVariable String category,
Model model) { ... }
And the urls I'm hitting:
http://localhost:8080/objects/2/xyz
http://localhost:8080/objects/2/xyz_mobile
Spring unable to find the handler and complains with No mapping found for HTTP request.
According to the Spring MVC documentation:
The
@RequestMappingannotation supports the use of regular expressions in URI template variables. The syntax is{varName:regex}where the first part defines the variable name and the second - the regular expression.
So, you should remove the space between : and regex, like the following:
@RequestMapping(value = "{objectId}/{objectName:[a-zA-Z-]+}", method = GET)
^ Space is removed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With