Grails URLMappings 使用错误URL

Grails URLMappings uses the wrong URL

GSP Code如何强制 Grails 在 UrlMappings.groovy 中使用正确的 URL 给定相同的路径,一个以 $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

您可以通过指定请求类型来强制执行它,例如Post、放置、删除、获取等

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

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

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

您也可以在映射中执行某种约束/逻辑来解决问题,但这可能会有点混乱。