以 Map 形式检索域对象实例
我想知道是否有一种方法可以将域实例检索为 Map,其中键是域对象的 id。
更具体地说,我想做 myDomainObject.list() 来返回 Map 而不是 List。
I wonder if there is a way to retreive domain instances as a Map where the key is the id of the domain object.
more specific i would like to do myDomainObject.list()
to return a Map instead of a List.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在域类中轻松创建此方法,例如:
You can create this method easily in your domain class, for example:
如果这不是您唯一需要它的地方,您还可以使用 Burts 代码通过 ExpandoMetaClass。
这将集中功能并保持域类的干净。
If this isn't the only place you need it, you could also use Burts code to extend eiter domain classes or the map itself via the ExpandoMetaClass.
This would centralize the functionality and keep your domain classes clean.