domain 部分
对应的 views 部分
并在 对应的 Controller的 save 中加入 partInstance.setCoding(params.id)
.
.
.
class Part {
String id
String name
static transients = ['coding']
void setCoding(String coding)
{
id = coding
}
String getCoding(){
return id
}
static mapping={
version false
id generator: 'assigned' //,column:'part_id'
}
.
.
.
对应的 views 部分
.
.
.
<g:form action="save" >
<div class="dialog">
<table>
<tbody>
<tr class="prop">
<td valign="top" class="name">
<label for="id"><g:message code="part.id.label" default="Id" /></label>
</td>
<td valign="top" class="value ${hasErrors(bean: partInstance, field: 'id', 'errors')}">
<g:textField name="id" maxlength="20" value="${partInstance?.id}" />
</td>
</tr>
<tr class="prop">
<td valign="top" class="name">
<label for="name"><g:message code="part.name.label" default="Name" /></label>
</td>
<td valign="top" class="value ${hasErrors(bean: partInstance, field: 'name', 'errors')}">
<g:textField name="name" maxlength="40" value="${partInstance?.name}" />
</td>
</tr>
.
.
.
并在 对应的 Controller的 save 中加入 partInstance.setCoding(params.id)
def save = {
def partInstance = new Part(params)
partInstance.setCoding(params.id)
if (partInstance.save(flush: true)) {
.
.
.