【发布时间】:2026-01-25 20:35:02
【问题描述】:
文档说,根据版本,访问 Domain.constraints 或 Domain.constrainedProperties 应该给出一个键值映射。
https://grails.github.io/grails2-doc/2.5.4/ref/Domain%20Classes/constraints.html
在运行时,静态约束属性是一个 Map,因此 Map 中的键是属性名称,与键关联的值是 ConstrainedProperty 的实例:
但是,使用 2.5+,在运行时访问约束属性不会提供映射,而是提供闭包,并且我无法访问 ConstrainedProperty 实例。
我也尝试使用 grails 类工具来访问静态属性
GrailsClassUtils.getStaticFieldValue(Domain,"constraints")//this is still a closure
GrailsClassUtils.getStaticFieldValue(Domain,"constrainedProperties")//null, this property doesn't exist below version 3.0
【问题讨论】:
标签: grails