在 Grails 中获取 bean 属性名称
我正在尝试编写一个标签,它将呈现我的 bean 属性和相应的值。我希望默认行为是渲染 bean 中的所有属性。所以我需要以某种方式从传递的 bean 中获取所有属性名称。
我想我可以使用 properties
映射,但是尽管有 bean 属性,但还有其他东西,我必须手动管理它,这可能容易出错。
我还考虑过使用 DefaultGrailsDomainClass ,它对于域类很方便,但对于命令对象来说毫无用处。
你曾经做过类似的事情并想出一些有用的东西吗?
I'm trying to write a tag, which will render my bean properties and corresponding values. I want the default behaviour be to render all properties from the bean. So I need somehow get all property names from passed bean.
I figured that I could use properties
map, but despite bean properties, there are also other things and I'd have to manage it by hand which may be error prone.
I also thought of using DefaultGrailsDomainClass
which is handy for domain classes, but is useless for command objects.
Have you ever done something similar and came up with something useful?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
就像这里所说,还有
persistentProperties
。但我相信你需要GrailsDomainClass.properties
- 不要与 Groovyproperties
混淆,前者用于域类。对于渲染,
GrailsDomainClassProperty.naturalName
也很有用。Like said here, there are also
persistentProperties
. But I believe you needGrailsDomainClass.properties
- don't confuse with Groovyproperties
, the former are for domain class.For rendering,
GrailsDomainClassProperty.naturalName
will also be useful.我已经使用
properties
完成了类似的事情,没问题。我的代码是:I've done similar thing by using
properties
, no problem. My code was: