您的位置:首页 > 其它

如何把groovy对象的全部属性取出,无需逐个访问

2017-03-13 09:50 260 查看
class why{
def name ="why"
def age = 15
def run() {
println 'Groovy world!'

}
public static void main(String[] args)
{
def t =  new why()
t.run()
def mapProperties = t.getProperties()
mapProperties.remove('class')//默认有自带class属性,移除减少数据传输量
println(mapProperties)
}
}

因工作中需要把从数据库获取查询出来的实体属性逐个取出,然后存入map,在发往前端,逐个遍历属性过于繁琐,故查找了下groovy 提供的方法来实现。就此记录一下。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: