加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-14 16:42:01 所属栏目:大数据 来源:网络整理
导读: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属性,移除
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 提供的方法来实现。就此记录一下。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读