如何获取我的域对象之一上仅用户定义属性的键/值的映射?
问题是,如果我自己这样做,我会得到我的属性加上类、元类、约束、闭包等......
我认为 Grails 可以相当容易地做到这一点,因为它是在脚手架代码中的某个级别完成的,对吗?我自己怎样才能做到这一点?
Try this
class Person{
String name
String address
}
def filtered = ['class', 'active', 'metaClass']
def alex = new Person(name:'alex', address:'my home')
def props = alex.properties.collect{it}.findAll{!filtered.contains(it.key)}
props.each{
println it
}
如果您使用它也有效alex.metaClass.surname = 'such'
。该属性将在each循环中显示
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)