gpt4 book ai didi

grails - 返回自定义验证器错误 Grails

转载 作者:行者123 更新时间:2023-12-04 22:51:43 26 4
gpt4 key购买 nike

我只收到默认验证器消息。我究竟做错了什么?

class Questao {


static hasMany = [alternativas:Alternativa]

static constraints = {

alternativas (validator: {val, obj ->
if(val.size() < 2)
return ['validator.message'] //custom message
})
}
}

/i18n
questao.alternativas.validator.message = "must be greater than two"

default.invalid.validator.message= Property [{0}] of class [{1}] with value [{2}] does not pass custom validation

谢谢

最佳答案

您正在返回一个包含您的消息代码的列表 - 您只需要返回代码:

alternativas validator: { val, obj ->
if (val.size() < 2) {
return 'validator.message' //custom message
}
}

关于grails - 返回自定义验证器错误 Grails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4111880/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com