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 提供的方法来实现。就此记录一下。
本文介绍了一种使用Groovy简化实体属性到Map转换的方法,通过实例演示如何将类的属性值快速转换为Map结构,便于前端展示。

1712

被折叠的 条评论
为什么被折叠?



