0

I have got stuck with the following. Lets say I have an url like

http://localhost:8080/a/somename-anyothername-onemorename-aAttributeId.html
http://localhost:8080/a/anyothername-onemorename-aAttributeId.html
http://localhost:8080/a/anyothername-onemorename-anyothername-anyothername-aAttributeId.html
...

In general the url may have a number of parts. My goal is to set the AttributeId part of the url above as a variable in @RequestMapping as it shown below

@Controller
@RequestMapping(value = "/**/a")
public class ProductPageController extends AbstractPageController
{

@RequestMapping(value = "/{attributeId:(?:[-a])(?!.*(?:[-a])).*}.html", method =      RequestMethod.GET)
     public String requestHandler(@PathVariable("attributeId") final String attributeId,   final Model model) {
          //method body
     }
}    
} 

My question is what I do wrong with my regex? Should I split the regex somehow to escape everything before the aAttributeId.html part as the following:

@RequestMapping(value = "/{unused:*.}{productCode:(?:[-a])(?!.*(?:[-a])).*}.html", method = RequestMethod.GET)

Thanks for ideas

Update: Answer for the question

The final mapping looks as the following:

@RequestMapping(value = "/**{attributeId:a(?:[^-]+)}.html", method = RequestMethod.GET)

1 Answer 1

1

How about:

-a([^-]+)\.html

NB: I don't know spring syntax.

Sign up to request clarification or add additional context in comments.

2 Comments

@CyrilDeba: There was a typo, is it ok now?
I accepted your answer but it was slightly modified by me (see the updated question). Thanks a lot!

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.