我的域类ID已映射到bookId
class Book {
int id
int bookId
String bookAuthor
static constraints = {
bookAuthor blank: false, maxSize:30
}
static mapping = {
version false
id generator: 'sequence',
params: [sequence:'s_book_seq'],
name: 'bookId'
}
}
这导致生成的show.gsp无法理解用于编辑和删除的ID。我能够修改编辑链接,使其识别bookId。但不确定如何修改删除按钮代码。请指教。
<g:form url="[resource:bookInstance, action:'delete']" method="DELETE">
<fieldset class="buttons">
<g:link class="edit" action="edit" id="${bookInstance.bookId}" ><g:message code="default.button.edit.label" default="Edit" /></g:link></td>
<g:actionSubmit class="delete" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');" />
</fieldset>
</g:form>
答案 0 :(得分:1)
您需要添加隐藏字段,以便在提交表单时发送id
参数,例如
<g:form url="[resource:bookInstance, action:'delete']" method="DELETE">
<g:hiddenField name="id" value="${bookInstance.bookId}" />
<fieldset class="buttons">
<g:link class="edit" action="edit" id="${bookInstance.bookId}" ><g:message code="default.button.edit.label" default="Edit" /></g:link></td>
<g:actionSubmit class="delete" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');" />
</fieldset>
</g:form>