简体   繁体   English

动态在grails域类中注入字段

[英]Inject field in a grails domain class dynamically

I have a problem in a grails application. 我在grails应用程序中有问题。 My application use a plugin to generate some domain models, I need to add a field to one of those domain models and I don't have the source code. 我的应用程序使用插件来生成一些域模型,我需要向这些域模型之一添加字段,但是我没有源代码。 Is there a way to do it dynamically? 有没有办法动态地做到这一点? For example using the GORM API the metaclass or something like that? 例如使用GORM API元类还是类似的东西?

You could probably just extend the class from the plugin and add your field. 您可能只需要从插件扩展类并添加您的字段即可。 That is a common thing to do with plugins like Spring Security Core. 这对于像Spring Security Core这样的插件是很常见的。

    class MyUser extends SecUser {
        String phoneNumber
        ...
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM