假设我有以下命令:
@Validateable
class MyCommand {
String cancel_url
String redirect_url
String success_url
static constraints = {
cancel_url nullable: false, validator: { url, obj ->
//some specific validation
//some common url validation
}
redirect_url nullable: false, validator: { url, obj ->
//some specific validation
//some common url validation
}
success_url nullable: false, validator: { url, obj ->
//some specific validation
//some common url validation
}
}
}
假设我想对任何 URL 字段执行一些常见的验证(例如,检查是否允许该域)。将这个常见的验证代码分解成一个单独的函数而不是在每个验证闭包中放置相同的块的语法是什么?