Grails 确定数据类型

Grails 确定数据类型,grails,groovy,Grails,Groovy,我的控制器中有以下代码: def cols = grailsApplication.getDomainClass('com.archie.Build').persistentProperties.collect {it.name} 上面的代码将允许我列出构建类中的所有属性名称。现在,我还想包括属性数据类型,即布尔值、字符串等 与输出类似的是: [floorType:String, floorWidth:Float, ......] 可能不完全像那样,或者类似,但只要我能返回它们的数据类型。有

我的控制器中有以下代码:

def cols = grailsApplication.getDomainClass('com.archie.Build').persistentProperties.collect {it.name}
上面的代码将允许我列出构建类中的所有属性名称。现在,我还想包括属性数据类型,即布尔值、字符串等

与输出类似的是:

[floorType:String, floorWidth:Float, ......]

可能不完全像那样,或者类似,但只要我能返回它们的数据类型。有人能帮忙吗?谢谢。

persistentProperties中的每个条目都是一个,这提供了对作为
类的
对象的属性类型的访问:

def props = [:]
grailsApplication.getDomainClass('com.archie.Build'
    ).persistentProperties.each {
      props[it.name] = it.type.name
    }
或者只需将
persistentProperties
数组本身传递给GSP,然后在那里提取
.name
.type

您可能还希望考虑使用<代码>约束属性而不是/除了<代码>持久性属性。

constrainedProperties
映射仅列出域类约束块中提到的那些属性,但此映射上的迭代器保证按属性在约束中列出的顺序返回属性。这就是默认脚手架的工作方式,因为我不知道有什么方法可以控制
persistentProperties
数组的顺序