InList约束来自Config.groovy属性的值 [英] InList constraints values from Config.groovy property
本文介绍了InList约束来自Config.groovy属性的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我定义了一个带有inList约束的字段的简单类,我想从Config.groovy文件中定义的属性加载约束列表。
这是class
class用户{
字符串电子邮件
字符串部门
静态约束= {
email unique:true
department inList:[ABC,DEF,EGF,ETC]
}
}
和config属性
app.departments = [ABC,DEF,EGF,ETC]
我想从config.groovy属性中加载我的inList约束值是否可能?
谢谢
解决方案
持有者可以在这种情况下使用。
import grails.util.Holders
class用户{
字符串电子邮件
字符串部门
静态约束= {
电子邮件唯一:真正
部门inList:Holders.co nfig.app.departments
}
}
// config
app.departments = [ABC,DEF,EGF,ETC ]
I defined a simple class with a field that has a inList constraints, I want to load constraints list from a property defined in Config.groovy file
This is the class
class User {
String email
String department
static constraints = {
email unique:true
department inList:["ABC", "DEF", "EGF", "ETC"]
}
}
and config property
app.departments = ["ABC", "DEF", "EGF", "ETC"]
i would like to load my inList constraints values from config.groovy property is this possible?
thanks
解决方案
Holders can be used in this case.
import grails.util.Holders
class User {
String email
String department
static constraints = {
email unique:true
department inList: Holders.config.app.departments
}
}
//config
app.departments = ["ABC", "DEF", "EGF", "ETC"]
这篇关于InList约束来自Config.groovy属性的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文