如何访问Java服务层中的Grails域类

如何访问Java服务层中的Grails域类

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

问题描述

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

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



我希望问题很清楚。这应该是每个人在一个规模合理的项目中都必须面对的标准问题。

谢谢。

解决方案

org.codehaus.groovy.runtime.InvokerHelper使这个非常简单;看到这个邮件列表线程:


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

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.

thanks.

解决方案

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域类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 04:38