用于友好URL的Struts2递归通配符映射

时间:2014-02-27 15:05:54

标签: recursion struts2 wildcard friendly-url

    <action name="en/articles/categories/*" class="it.cms.article.action.SearchArticleCustom">
        <param name="locale">en</param>
        <param name="categoryFriendlyUrl">{1}</param>
        <result name="success">/pages/article/search_article.jsp</result>
    </action>

    <action name="en/articles/categories/*/*" class="it.cms.article.action.SearchArticleCustom">
        <param name="locale">en</param>
        <param name="categoryFriendlyUrl">{2}</param>
        <result name="success">/pages/article/search_article.jsp</result>
    </action>

    <action name="en/articles/categories/*/*/*" class="it.cms.article.action.SearchArticleCustom">
        <param name="locale">en</param>
        <param name="categoryFriendlyUrl">{3}</param>
        <result name="success">/pages/article/search_article.jsp</result>
    </action>

所以,我的情况是类别可以嵌套而没有限制。 当前的struts-config文件对于3级子类别非常有用。

我是否可以将此代码设置为“递归”以涵盖无限级别的子类别?

1 个答案:

答案 0 :(得分:1)

完全未经测试,但我会尝试类似的事情:

<action name = "en/articles/categories**/*" 
       class = "it.cms.article.action.SearchArticleCustom">

    <param  name = "locale">en</param>
    <param  name = "categoryFriendlyUrl">{2}</param>

    <result name = "success">/pages/article/search_article.jsp</result>

</action>

来自the documentation

  

**:匹配零个或多个字符,包括斜杠('/')字符。