4

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.

1
  • Remove the space between : and regex and Try again. Commented May 19, 2016 at 16:47

1 Answer 1

4

According to the Spring MVC documentation:

The @RequestMapping annotation 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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.