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 提供的方法来实现。就此记录一下。
转载请注明原文地址: https://ju.6miu.com/read-38802.html