0
我遇到以下問題。可以說我有一個像@RequestMapping中的正則表達式
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
...
一般來說,url可能有多個部分。我的目標是設置URL的屬性Id以上部分作爲@RequestMapping變量如下圖所示
@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
}
}
}
我的問題是什麼,我做錯了我的正則表達式?我應該以某種方式拆分正則表達式的aAttributeId.html一部分以下之前,什麼都逃不過:
@RequestMapping(value = "/{unused:*.}{productCode:(?:[-a])(?!.*(?:[-a])).*}.html", method = RequestMethod.GET)
感謝想法
更新:回答這個問題
最終的映射看起來以下內容:
@RequestMapping(value = "/**{attributeId:a(?:[^-]+)}.html", method = RequestMethod.GET)
感謝您的回答,但它不能很好地工作 –
@CyrilDeba:有一個錯字,現在可以嗎? – Toto
我接受了你的答案,但它被我稍作修改(請參閱更新後的問題)。非常感謝! –