如何访问 Java 服务层中的 Grails 域类? [英] How to access Grails domain classes in Java service layer?

查看:15
本文介绍了如何访问 Java 服务层中的 Grails 域类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Java/Spring 的服务层中使用 grails 域类(在 groovy 中).

How can I use grails domain classes (which is in groovy) in service layer which is in Java/Spring.

当使用 grails MVC 时,一切都很好,因为我可以使用控制器访问域对象并在它们上调用 CRUD 和其他动态方法.但是,我想知道是否有一种干净的方法可以从 Java 中做到这一点——比如说服务层.例如,我可能想开发一个报告框架,我需要使用域对象来访问数据库.

When using the grails MVC, everything is fine as I can use controller to access domain objects and call CRUD and other dynamic methods on them. But, what I am wondering is is there a clean way to do it from Java - say the service layer. For example, I may want to develop a reporting framework where I need to use domain objects to access the DB.

我希望问题很清楚.这应该是每个人在合理规模的项目中都必须面临的标准问题.我只是想知道它是如何解决的..也许我在这里遗漏了一些东西.

I Hope the question is clear. This should be a standard problem that everybody must have faced in a reasonably sized project. I am just wondering how it is solved..maybe I am missing something here.

谢谢.

推荐答案

org.codehaus.groovy.runtime.InvokerHelper 使这变得非常简单;请参阅此邮件列表线程:http://grails.1312388.n4.nabble.com/Calling-Dynamic-Finders-on-Domain-Class-via-the-MetaClass-td1596496.html

org.codehaus.groovy.runtime.InvokerHelper makes this pretty straightforward; see this mailing list thread: http://grails.1312388.n4.nabble.com/Calling-Dynamic-Finders-on-Domain-Class-via-the-MetaClass-td1596496.html

这篇关于如何访问 Java 服务层中的 Grails 域类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆