入门客AI创业平台(我带你入门,你带我飞行)
博文笔记

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

创建时间:2017-03-13 投稿人: 浏览次数:1629
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 提供的方法来实现。就此记录一下。

声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。