代码之家  ›  专栏  ›  技术社区  ›  Neel Krishna

Grails URLMappings使用了错误的URL

  •  0
  • Neel Krishna  · 技术社区  · 9 年前

    GSP Code 如何强制Grails在中使用正确的URL UrlMappings.groovy 给定相同的路径,其中一条以 $action 另一个以 $id ? 当通过GSP文件触发操作时,我的程序进入 id URL,导致错误。

    Image shows the two URLs in question. I need to trigger the first URL, $action, on click of a button but instead the second URL is triggered

    2 回复  |  直到 9 年前
        1
  •  0
  •   Nick Larson    9 年前

    在这里,您将遇到困难,因为$id和$action在分配之前只是变量名。他们不知道你正在发送一个id或一个动作,只知道url匹配一个模式。你可以这样做。

    "/workflow/**/$siteId/**/$iteration/**/$action?/$id?" (controller:"*****")
    

    您必须始终指定您的操作, ***/list/123 ***/someAction 将匹配,但不匹配 ***/123 .

    你也可以在映射中做一些约束/逻辑来整理事情,但这可能会有点混乱。

        2
  •  0
  •   Vinay Prajapati Mahfujur Rahman    9 年前

    您可以通过指定请求类型来强制执行,例如Post、Put、delete、get等。