我在 grails 3.3.3 中编写自定义验证器(命令)时遇到了一些问题。具体来说,我正在尝试验证其正文由项目列表组成的 POST 请求。这就是我所拥有的...
命令:
class VoteCommand implements Validateable {
List<VoteItem> postList = [].withLazyDefault { new ListItem() }
static constraints = {
postList nullable: false
}
class ListItem implements Validateable {
String tag
String some_id
static constraints = {
some_id nullable: false, blank: false
tag nullable: false, blank: false
tag inList: Tag.values() as List
}
}
}
和有效载荷:
{
"noteVotesButWorks": [
{
"tag": "good"
},
{
"tag": "bad"
}
]
}
此有效负载通过了我的控制器操作中的验证检查。
def save(VoteCommand command) {
println(command.errors) //grails.validation.ValidationErrors: 0 errors
if (command.hasErrors()) {
respond params.errors, view: 'create'
} else {
withFormat {
'*' { render status: CREATED }
}
}
}
对此操作发出 POST 请求后,我得到一个201
并grails.validation.ValidationErrors: 0 errors
打印到标准输出。
拜托,这里有人可以给我一些指示吗?