这是我的域类
class ReturnReason implements Serializable {
Long returnReasonId
Long languageId
String name
int hashCode() {
def builder = new HashCodeBuilder()
builder.append returnReasonId
builder.append languageId
builder.toHashCode()
}
boolean equals(other) {
if (other == null) return false
def builder = new EqualsBuilder()
builder.append returnReasonId, other.returnReasonId
builder.append languageId, other.languageId
builder.isEquals()
}
static mapping = {
id composite: ["returnReasonId", "languageId"]
version false
}
static constraints = {
name maxSize: 128
}
}
这是我的控制器代码,用于保存我的域类。
def save() {
ReturnReason returnReasonInstance = new ReturnReason(params)
returnReasonInstance.languageId = 1
if (!returnReasonInstance.save(flush: true)) {
render(view: "create", model: [returnReasonInstance: returnReasonInstance])
}
redirect(action: "list")
}
尝试保存在我的控制器中而不是returnReasonId中存在错误,即returnReasonId拒绝值null。如何解决它。??
答案 0 :(得分:0)
在保存操作中写入validate:false
def save() {
ReturnStatus returnStatusInstance = new ReturnStatus(params)
returnStatusInstance.languageId = 1
if (!returnStatusInstance.save(validate: false, flush: true)) {
render(view: "create", model: [returnStatusInstance: returnStatusInstance])
}
redirect(action: "list")
}