我有一个域对象,其属性称为date:
class Item implements Comparable{
Date date
}
我该如何通过以下方式访问该日期:
Item.list().each{
Date d = it.get("date")
}
我知道我可以做
Date d = it.date
,但是我希望能够从我的域对象中选择一个属性并访问它而无需使用.property。
最佳答案
试试这个..,。
Item.list().each {
Date d = it.properties.get("date")
}
要么
Item.list().each {
Date d = it.getProperty("date")
}
关于grails - 如何使用属性名称访问域属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19796027/