我正在使用 Grails 2.4.2。我有一个表单,可以在其中添加、编辑或删除任何数据或行。但我想从索引中按需删除一行。为此,我在表格单元格中为每一行添加了一个链接。但它给出了 405 错误,即:
所请求的资源不允许指定的 HTTP 方法
我的索引.gsp:
<table>
<thead>
<tr>
<g:sortableColumn property="address" title="${message(code: 'userInfo.address.label', default: 'Address')}" />
<g:sortableColumn property="name" title="${message(code: 'userInfo.name.label', default: 'Name')}" />
<g:sortableColumn property="name" title="${message(code: 'userInfo.name.label', default: 'Action')}" />
</tr>
</thead>
<tbody>
<g:each in="${userInfoInstanceList}" status="i" var="userInfoInstance">
<tr class="${(i % 2) == 0 ? 'even' : 'odd'}">
<td><g:link action="show" id="${userInfoInstance.id}">${fieldValue(bean: userInfoInstance, field: "address")}</g:link></td>
<td>${fieldValue(bean: userInfoInstance, field: "name")}</td>
<td><g:link action="delete" id="${userInfoInstance.id}">Delete</g:link></td>
</tr>
</g:each>
</tbody>
</table>
接下来我可以尝试什么?
我认为您在控制器中使用“allowedMethods”,就像这样
static allowedMethods = [delete: "POST"]
http://grails.github.io/grails-doc/2.4.2/ref/Controllers/allowedMethods.html
但是当您使用链接标签库时,您正在发出 GET 请求而不是 POST