recoveryDetailInstance

recoveryDetailInstance

field 'adjustmentType': rejected value [null]上保存期间出现验证错误,我对此错误感到有点困惑,因为我将映射设置为允许为nullable

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())
}

最佳答案

nullable是一个约束,而不是数据库映射。相反,它属于constraints块。

static constraints = {
    adjustmentType nullable: true
}

09-05 16:35