开发者

How do I determine if a class is a Grails domain object?

For an arbitrary object what is the easiest way to determine if the type of the object is a Grails do开发者_如何学Pythonmain class?


You can use the GrailsApplication for that. Add a dependency injection to your controller or service:

def grailsApplication

and then you can use it like this:

def foo = ...
if (grailsApplication.isDomainClass(foo.getClass()) {
    ...
}


Found the following snippet at https://svn.intuitive-collaboration.com/RiskAnalytics/trunk/riskanalytics-grails/src/java/org/codehaus/groovy/grails/web/binding/GrailsDataBinder.java

DomainClassArtefactHandler.isDomainClass(clazz)

The javadoc is here: http://grails.org/doc/latest/api/org/codehaus/groovy/grails/commons/DomainClassArtefactHandler.html#isDomainClass(java.lang.Class)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜