Grails拒绝值[null]

时间:2015-07-09 16:33:55

标签: grails groovy

我在field 'adjustmentType': rejected value [null]保存期间收到验证错误我对这个错误感到有些困惑,因为我的映射设置为允许nullables

static mapping = {  
    columns{
        adjustmentType column: 'adjustment_type', length: 10, sqlType:"char", nullable: true
    }
}

我不明白的另一部分是为什么我得到的是异常而不是验证消息。

我有以下代码

<g:hasErrors bean="${recoveryDetailInstance}">
    <ul class="errors" role="alert">
        <g:eachError bean="${recoveryDetailInstance}" var="error">
            <li
                <g:if test="${error in org.springframework.validation.FieldError}">data-field-id="${error.field}"</g:if>><g:message
                    error="${error}" /></li>
        </g:eachError>
    </ul>
</g:hasErrors>

控制器

@Transactional
def update() {  
    def recoveryDetailInstance = RecoveryDetail.get(new RecoveryDetail(params));


    if (recoveryDetailInstance == null) {
        redirect (uri:'/')
        return
    }

    recoveryDetailInstance.save(flush:true,failOnError:true)

    redirect (controller:"recoveryDetail", action:"edit", params:recoveryDetailInstance.getPK())
}

1 个答案:

答案 0 :(得分:1)

nullable是一个约束,而不是数据库映射。它取而代之的是constraints块。

static constraints = {
    adjustmentType nullable: true
}