开发者

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

开发者 https://www.devze.com 2023-03-12 09:08 出处:网络
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 injectio

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

精彩评论

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