Reputation: 1210
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)
Upvotes: 0
Views: 3077