1

这是我的域类

 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。怎么修。??

4

1 回答 1

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")
}
于 2013-01-08T09:13:30.993 回答